我有下面的模型
public class Student
{
    public int Id { get; set; }
    private string reference;
    public string Reference
    {
        get
        {
            return this.reference;
        }
        set
        {
            this.reference = "ST" + Id;
        }
    }
}我正在尝试写到数据库引用列,如
Id - Reference
1   - ST1
2   - ST2我的上下文类具有以下配置
public class SchoolContext : DbContext
{
    public DbSet<Student> Student { get; set; }
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Student>()
        .Property(b => b.Id)            
        .ValueGeneratedOnAdd();
        modelBuilder.Entity<Student>()
        .Property(b => b.Reference)
        .HasComputedColumnSql("[Id]")
        .ValueGeneratedOnAdd();
    }
}但我没有得到我想要的。请记住,我不想在sql server中生成
发布于 2018-03-08 09:43:31
好吧,让我们看看:
事实:
与EF的解决方案:
或者,你可以考虑:
对不起,这可能不能完全解决您的问题,因为您的限制和限制。
祝你好运!
https://stackoverflow.com/questions/49139879
复制相似问题