数据库优先没有来自数据库的主键

时间:2014-06-23 20:06:38

标签: entity-framework

我使用数据库优先构建我的DataContext并且我有这个实体:

public partial class Salutation
{
    public int Id { get; set; }
    public string SalutationShort { get; set; }
    public string SalutationLong { get; set; }
    public string LetterSalutation { get; set; }
}

我这样用它:

var s = new Salutation()
        {
            SalutationShort = "Mr.",
            LetterSalutation = "Mister"
        };

context.Salutations.Add(s);
var xx = context.SaveChanges();

问题:我无法强制数据库生成有效的ID。

第一次尝试给出' 0'作为主键,以下调用会导致错误,因为' 0' 0已经在使用中。

我错过了什么吗?

顺便问一下,有什么理由

protected override void OnModelCreating(DbModelBuilder modelBuilder)

不被称为

由于

彼得

0 个答案:

没有答案
相关问题