That isn't the Id of an Entity Framework auto incrementing field.

code-first ef-code-first entity-framework

Question

I am aware that adding an auto incrementing field to one of my EF Code First objects is not the best option, but I have no other choice. The Id, which is a GUID, is NOT this field.

Is it possible for me to provide the auto incrementing field in code, or would constructing the column myself and specifying in the database that its auto incrementing work instead?

1
42
4/16/2017 3:44:05 AM

Accepted Answer

This characteristic may be marked withDatabaseGenerated(DatabaseGeneratedOption.Identity) Only one identification column is permitted per table in EF.

public class Foo
{
    [Key]
    public Guid Id { get; set; }

    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long Bar { get; set; }
}
63
5/3/2012 8:36:30 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow