日期:2014-05-20  浏览次数:20767 次

Entity Framework 如何创建基类
今天刚接触Entity Framework,确实在简单使用非常方便  
  我现在有一个需求 将对象的公共字段 如 id createDate 等 提取出来作为BaseEntity
  在xxxModelFirst.Designer.cs 的model对象继承这个BaseEntity



    public partial class BaseEntity : EntityObject
    {

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
        [DataMemberAttribute()]
        public global::System.Int32 Id
        {
            get
            {
                return _Id;
            }
            set
            {
                if (_Id != value)
                {
                    OnIdChanging(value);
                    ReportPropertyChanging("Id");
                    _Id = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("Id");
                    OnIdChanged();
                }
            }
        }
        private global::System.Int32 _Id;
        partial void OnIdChanging(global::System.Int32 value);
        partial void OnIdChanged();

        /// <summary>
        /// 没有元数据文档可用。
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
        [DataMemberAttribute()]
        public global::System.Boolean Enable
        {
            get
            {
                return _Enable;
            }