Search code examples
c#entity-frameworkidentity-column

Letting EF 4.1 auto-create an identity column


Suppose you have

public class A
{
   public string _myString;
}

And this context:

public class MyContext: DbContext
{
    public DbSet<A> myASet{ get; set; }
}

Now, is there a way to tell EF to generate an identity column for myASet?

I don't want to add an ID field to class A, so I wonder if EF could do this. Many thanks,

Juergen


Solution

  • You must add ID column to your class if you want to have it in the database. Also in EF each entity must have mapped primary key.