加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – Orchard CMS 1.x [文档存储] – 混合记录支持和记录

发布时间:2020-12-16 09:53:51 所属栏目:asp.Net 来源:网络整理
导读:我正在关注Bertrand Le Roy的指南,将OrchardCMS迁移到Document Storage(1.x分支预发布) http://weblogs.asp.net/bleroy/archive/2013/11/04/the-shift-how-orchard-painlessly-shifted-to-document-storage-and-how-it-ll-affect-you.aspx 以下是我的示例代
我正在关注Bertrand Le Roy的指南,将OrchardCMS迁移到Document Storage(1.x分支预发布)

http://weblogs.asp.net/bleroy/archive/2013/11/04/the-shift-how-orchard-painlessly-shifted-to-document-storage-and-how-it-ll-affect-you.aspx

以下是我的示例代码中的一些摘录,旨在将记录支持和无记录属性混合到ContentPart中.

移民

public int Create() {
        SchemaBuilder.CreateTable("CustomerPartRecord",table => table
                .ContentPartRecord()
                .Column<string>("Name")
            );

        ContentDefinitionManager.AlterPartDefinition("CustomerPart",builder => builder
            .Attachable());

        ContentDefinitionManager.AlterTypeDefinition("Customer",type => type
                .WithPart("CommonPart")
                .WithPart("Title")
                .WithPart("CustomerPart")
                .Creatable());
        return 1;
    }

ContentPartRecord

public class CustomerPartRecord : ContentPartRecord {
    public virtual string Name { get; set; }
    public virtual string Phone { get; set; }
    public virtual string Email { get; set; }
}

ContentPart

public class CustomerPart : ContentPart<CustomerPartRecord>
{
    public string Name
    {
        get { return Record.Name; } // tried "return Retrieve(x=>x.Name);"
        set { Record.Name = value; } // tried "return Store(x=>x.Name,value);"
    }
    public string Phone
    {
        get { return this.Retrieve(x => x.Phone); } //Recordless property
        set { this.Store(x => x.Phone,value); }
    }
    public string Email
    {
        get { return this.Retrieve(x => x.Email); } //Recordless property
        set { this.Store(x => x.Email,value); }
    }
}

尝试添加新记录时引发以下错误

could not insert: [Customers.Models.CustomerPartRecord#28][SQL: INSERT INTO Teknorix_Customers_CustomerPartRecord (Name,Phone,Email,Id) VALUES (?,?,?)] ---> System.Data.SqlServerCe.SqlCeException: The column name is not valid. [ Node name (if any) =,Column name = Phone ]

如果我添加手机和电话,这绝对可以. DB中的电子邮件列.但随后它将数据写入2个位置.在xml中,它只会插入手机和电子邮件字段.在表格中,它将插入整个记录.

我知道如果我使用Retrieve()代替this.Retrieve()然后它会将整个记录存储在两个地方等等……

但我感兴趣的是只在XML信息集中只有一些字段,而在记录表中只有一些字段.我在这做错了什么?

解决方法

如果您的部件有记录,您仍然可以仅在信息集中定位属性,而不需要存在记录属性.为此,请使用此功能获取信息集.如< InfosetPart>().然后,使用InfosetHelper中的扩展方法,例如infosetPart.Retrieve< string>(“Phone”)和infosetPart.Store< string>(“Phone”,value).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读