62,025
社区成员
发帖
与我相关
我的任务
分享
public class ArticleMap:EntityTypeConfiguration<Article>
{
public override void Map(EntityTypeBuilder<Article> builder)
{
builder.ToTable("Article");
builder.HasKey(p => p.Id);
builder.Property(p => p.Title).IsRequired(true);
builder.Property(p => p.Content).IsRequired();
builder.Property(p => p.MetaTitle).HasMaxLength(400);
builder.Property(p => p.MetaKeywords).HasMaxLength(400);
builder.Property(p => p.Content).HasColumnType("mediumtext");
//定义外键,
builder.HasOne(f => f.Category).WithMany(p => p.Articles).HasForeignKey(p => p.CategoryId);
}
}
public class Users
{
[Key]
public int id { get; set; }
public virtual ICollection<Orders> Orders { get; set; }
}
public class Orders
{
[Key]
public int ID { get; set; }
public int userid { get; set; }
public string orderno { get; set; }
[ForeignKey("userid")]
public virtual Users Users { get; set; }
}