2017-04-12 3 views
0

Umbraco CMSを初めて使用しています。私は私のプロジェクトでUi-O-Maticプラグインを使用しています。
Ui-O-Maticは、データベースのCRUD操作を容易にします。しかし、私はファイル、テキストエリアなどのバックオフィスコントロールを使いたいです。
Ui-O-Matic UmbracoのUIOMaticFieldまたはバックオフィスのコントロールを使用

このように、私はdatabase.csファイルのUIOMaticFielldを使用しています。

[Column("newsDetail")] 
[UIOMaticField("News Detail","Add Details",View ="textarea")] 
public string newsDetail { get; set; } 

[Column("newsImage")] 
[UIOMaticField("Image","Upload Image",View ="file")] 
public string newsImage { get; set; } 

問題は私がデータベースを変更したときにデータベースの変更を取得するためにdatabase.ttファイルを更新する必要があるという問題です。しかし、database.csファイルと私の以前の変更を再作成します:

[UIOMaticField("News Detail","Add Details",View ="textarea")] 

database.csファイルから削除します。そして、毎回私は同じ変更を行う必要があります。
私のカスタム変更をそのままにするにはどうすればいいですか私はdatabase.ttファイルを更新しますか?
CRUD操作を行う他の良い方法も望ましいです。

答えて

1

多くのグーグルで検索したところ、database.csファイルが自動生成されるため、カスタム変更を行わないでください。
バックオフィスコントロールを使用する別の方法が見つかりました。私はここで説明しましょう、他の人に役立つかもしれません。

databse.csファイルにUIOMatoicFieldを書き込むのではなく、同じことを行うモデルを作成します。
は、その後、以下のように新しいモデルを作成し、「モデル/生成/ database.tt」ファイルの変更

// Settings 
    ConnectionStringName = "umbracoDbDSN";   // Uses last connection string in config if not specified 
    Namespace = "Generator"; 
    RepoName = ""; 
    GeneratePocos = true; 
    ClassPrefix = ""; 
    ClassSuffix = ""; 

    // Read schema 
    var tables = LoadTables(); 
    tables["Course"].Ignore = true; // Prevents table to include in databse.cs file 
    tables["News"].Ignore = true; 
if (tables.Count>0) 
    { 
#> 
<#@ include file="UIOMatic.Generator.ttinclude" #> 
<# } #> 

下にしてください。例えば、 "Models \ NewsModel.cs"

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using UIOMatic.Attributes; 
using UIOMatic.Enums; 
using UIOMatic.Interfaces; 
using Umbraco.Core.Persistence; 
using Umbraco.Core.Persistence.DatabaseAnnotations; 

namespace EdumentUIOMatic.Models 
{ 
    [Umbraco.Core.Persistence.TableName("News")] 
    [PrimaryKey("newsId")] 
    [UIOMatic("News", "icon-box-open", "icon-box-open", RenderType = UIOMaticRenderType.List, ConnectionStringName = "umbracoDbDSN")] 
    public class NewsModel: IUIOMaticModel 
    { 
     [UIOMaticIgnoreField] 
     [Column("newsId")] 
     public int newsId { get; set; } 

     [Column("newsTitle")] 
     [UIOMaticField("News Title", "Add Title")] 
     public string newsTitle { get; set; } 

     [Column("newsDetail")] 
     [UIOMaticField("News Detail", "Add Details", View = "textarea")] 
     public string newsDetail { get; set; } 

     [Column("newsImage")] 
     [UIOMaticField("Image", "Upload Image", View = "file")] 
     public string newsImage { get; set; } 



     [Column("isDeleted")] 
     [UIOMaticField("Hide News", "Check if you want to hide this news")]   
     public bool isDeleted { get; set; } 



     [System.Web.Http.AcceptVerbs("GET", "POST")] 
     public IEnumerable<Exception> Validate() 
     { 
      return new List<Exception>(); 
     } 
    } 
} 

データベースを更新するためにdatabase.ttファイルをリロードすると、コードは削除されません。

関連する問題