是否可能将map对象作为具有valuegenerateadd typeof int的标识列? 我尝试这样,但这没有帮助。我有错误
身份值生成不能用于实体类型“ Article”上的属性“ Id”,因为属性类型为“ ArticleId”。身份值生成只能与带符号的整数属性一起使用。
public class ArticleId
{
public int Value { get; private set; }
public ArticleId(int value)
{
Value = value;
}
}
public class Article {
public ArticleId Id { get; set; }
public string Name { get; set; }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var converter = new ValueConverter<ArticleId, int>(
v => v.Value,
v => new ArticleId(v));
modelBuilder
.Entity<Article>()
.Property(p => p.Id)
.HasConversion(converter).ValueGeneratedOnAdd().UseIdentityColumn();
base.OnModelCreating(modelBuilder);
}