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;
}
set
{
OnEnableChanging(value);
ReportPropertyChanging("Enable");
_Enable = StructuralObject.SetValidValue(value);
ReportPropertyChanged("Enable");
OnEnableChanged();
}
}
private global::System.Boolean _Enable;
partial void OnEnableChanging(global::System.Boolean value);
partial void OnEnableChanged();
/// <summary>
/// 没有元数据文档可用。
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
[DataMemberAttribute()]
public Nullable<global::System.DateTime> CreateDate
{
get
{
return _CreateDate;
}
set
{
OnCreateDateChanging(value);
ReportPropertyChanging("CreateDate");
_CreateDate = StructuralObject.SetValidValue(value);
ReportPropertyChanged("CreateDate");
OnCreateDateChanged();
}
}
private Nullable<global::System.DateTime> _CreateDate;
partial void OnCreateDateChanging(Nullable<global::System.DateTime> value);
partial void OnCreateDateChanged();
}
[解决办法]
一样建,只是要改下Entity设置,只加载id createDate
[解决办法]
lz 可以尝试用CodeFirst 的方式来实现。
[解决办法]
CodeFirst 是先写model 然后在创建数据库吗?
我晚上回去试一下 刚接触 有点陌生
[解决办法]