62,243
社区成员




public enum OpType
{
Create = 0,
Update = 1,
Delete = 2
}
public abstract class Entity
{
public Entity()
{
Id = Infrastructure.GuidHelper.NewGuid();
}
public System.Guid Id { get; set; }
}
public class OperationLog : Entity
{
private OPType _Type = OPType.Create;
public OperationLog(OPType type)
{
this.ParentId = Infrastructure.GuidHelper.NewGuid();
this.UserId = Infrastructure.GuidHelper.NewGuid();
this._Type = type;
}
/// <summary>
/// 操作时间
/// </summary>
public DateTime DateTime
{
get; set;
}
/// <summary>
/// 外键 所有关联表的ID
/// </summary>
public Guid ParentId
{
get; set;
}
/// <summary>
///类型 0Create,1UPdate,2Delete
/// </summary>
public virtual OPType Type
{
get; set;
}
/// <summary>
/// 操作用户编号
/// </summary>
public Guid UserId
{
get; set;
}
}
public class OperationLog : Entity
{
public OperationLog(OPType type)
{
this.Title=String.Empty;
this.Content= String.Empty;
this.Create = new OperationLog (OpType.Create);
}
/// <summary>
/// 文章标题
/// </summary>
public DateTime Title
{
get; set;
}
/// <summary>
/// 文章内容
/// </summary>
public String Content
{
get; set;
}
/// <summary>
/// 创建操作人,不为空
/// </summary>
public OperationLog Create
{
get; set;
}
/// <summary>
/// 最后更新操作人,可以为空
/// </summary>
public OperationLog Update
{
get; set;
}
/// <summary>
/// 删除操作人,可以为空
/// </summary>
public OperationLog Delete
{
get; set;
}
}
public partial class ArticleMap
: System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<Article>
{
public ArticleMap()
{
// table
ToTable("Frm_Article", "dbo");
// keys
HasKey(t => t.Id);
// Properties
Property(t => t.Id)
.HasColumnName("Id")
.IsRequired();
Property(t => t.ParentId)
.HasColumnName("F_ParentId")
.IsRequired();
Property(t => t.Title)
.HasColumnName("F_Title")
.HasMaxLength(255)
.IsRequired();
// Create 不能为空
?????
// Update 可以为空
??????????
// Delete 可以为空
??????????
}
使用Data Annotations:
//第一联系人
[InverseProperty("PrimaryContactFor")]
public Person PrimaryContact { get; set; }
//第二联系人
[InverseProperty("SecondaryContactFor")]
public Person SecondaryContact { get; set; }
或使用Fluent API:
modelBuilder.Entity<Lodging>().HasOptional(l => l.PrimaryContact).WithMany(p => p.PrimaryContactFor);
modelBuilder.Entity<Lodging>().HasOptional(l=>l.SecondaryContact).WithMany(p=>p.SecondaryContactFor);