我正在努力理解如何将这许多注释放入fluent api中。我只是不知道表示列顺序的语法。
public class UserNotification
{
[key]
[Column(Order = 1)]
public string UserId { get; set;}
[key]
[Column(Order = 2)]
public int NotificationId {get; set;}
public ApplicationUser User{get; set;}
public Notification Notification {get; set;}
}我知道fluent Api会是这样的:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserNotification>()
.HasKey(n => new {n.UserId, n.NotificationId});
// What about the Column Order?
}发布于 2017-12-15 14:44:28
您可以按以下方式读取Key和Column数据注释:
UserNotification有一个键,由UserId和NotificationId列组成,UserId是第一列,NotificationId是第二列。
也就是说,列order属性仅用于确定复合主键上下文中的列是第一列、第二列等等。
Fluent API不需要这样做,因为您既描述了键列,也描述了它们在HasKey表达式中的顺序:
modelBuilder.Entity<UserNotification>()
.HasKey(n => new { n.UserId, n.NotificationId });
// ^ ^
// first second换句话说,你做得很正确,不需要采取进一步的行动。
https://stackoverflow.com/questions/47834039
复制相似问题