EPR类企业管理系统

在我们现有系统基础上或全新开发,提供定制服务
为您的企业高效快速实施ERP,WMS,MES,CRM管理系统
全面管控物料仓库、销售业务、采购业务、仓库业务
生产过程、质量检验、组织架构、业务报表


定制
QQ:460-3528

开发
QQ群:3360-90194

源码
微信:136-3650-3721

实体框架中的引用属性

下面的示例说明了如何在Entity Framework Code First类中实现引用(外键,复杂类型)属性

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Editors;
using DevExpress.Persistent.Base;
// ...
[DefaultClassOptions]
public class ReferencedPropertiesObject : IXafEntityObject, IObjectSpaceLink {
    public int Id { get; set; }
    // Displayed in a lookup control: 
    public virtual ReferencedObject LookupReferencedObject { get; set; }
    // Displayed in a set of editors. Each editor represents an individual property of the referenced object: 
    [Aggregated, ExpandObjectMembers(ExpandObjectMembers.Always)]
    public virtual ExpandPropertiesObject ExpandPropertiesObject { get; set; }
    // Displayed in a Detail Property Editor that shows a referenced object's Detail View: 
    [Aggregated, EditorAlias(EditorAliases.DetailPropertyEditor)]
    [ExpandObjectMembers(ExpandObjectMembers.Never)]
    public virtual EmbeddedDetailViewObject EmbeddedDetailViewObject { get; set; }
    // Displayed in a button edit that invokes a referenced object's Detail View in a separate modal window: 
    [Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never)]
    public virtual PopupDetailViewObject PopupDetailViewObject { get; set; }

    #region IXafEntityObject members
    public void OnCreated() {
        EmbeddedDetailViewObject = ObjectSpace.CreateObject<EmbeddedDetailViewObject>();
        ExpandPropertiesObject = ObjectSpace.CreateObject<ExpandPropertiesObject>();
    }
    public void OnLoaded() { }
    public void OnSaving() { }
    #endregion

    #region IObjectSpaceLink members
    public IObjectSpace ObjectSpace { get; set; }
    #endregion
}

请注意,引用属性应在EF中声明为虚拟

如果将“详细信息属性编辑器”用作参考属性,或将ExpandObjectMembers属性应用于参考属性,则在创建新的父对象时需要初始化此类属性。否则,引用属性的字段将为只读。初始化应通过以下方式进行:

上面的代码演示了这些步骤。

转载保留此链接,注明出处