在 Ui-O-Matic Umbraco 中使用 UIOMaticField 或后台控制

Use UIOMaticField or backoffice controls in Ui-O-Matic Umbraco

我是 Umbraco CMS 的新手。我在我的项目中使用 Ui-O-Matic 插件。
Ui-O-Matic 允许对数据库进行简单的 CRUD 操作。但我想使用文件、文本区域等后台控件

所以我在 database.cs 文件中像这样使用 UIOMaticField。

 [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 文件?
其他更好的增删改查方式也是可取的。

经过大量谷歌搜索后,我发现由于 database.cs 文件是自动生成的,所以我不能在其中进行自定义更改。
我找到了另一种使用后台控制的方法。让我在这里解释一下,可能会对其他人有所帮助。

不要在 databse.cs 文件中编写 UIOMatoicField,而是创建模型来执行相同的操作。
在 "Models/Generated/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 文件以获取更新的数据库,您的代码将不会被删除。