2017-04-12 32 views
0

我是Umbraco CMS的新手。我在我的項目中使用了Ui-O-Matic插件。
Ui-O-Matic允許對數據庫進行簡單的CRUD操作。但我想要使用backoffice控件,如文件,textarea等。
在Ui-O-Matic Umbraco中使用UIOMaticField或backoffice控件

因此我在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

經過googling很多,我發現,因爲database.cs文件是自動生成的,我不能做自定義更改。
我發現了另一種使用backoffice控件的方法。讓我在這裏解釋一下,可能會對其他人有所幫助。

而不是寫在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文件以獲取更新的數據庫,您的代碼將不會被刪除。

相關問題