We have a database with a tables called \'Sites\' This table has the columns, SiteID, Name, Tags, Description, URI, with SiteID being a primary key (It is not set as an Iden
public class Sites
{
[Required, Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public int SiteID { get; set; }
public string Name { get; set; }
public string Tags { get; set; }
public string Description { get; set; }
public string URI { get; set; }
}
DbContext
. public class CMSModels : DbContext
{
//public DbSet<ContentTypeModel> ContentType { get; set; }
//public DbSet<LayoutModel> Layout { get; set; }
//public DbSet<PageModel> Page { get; set; }
//public DbSet<PageZoneModel> PageZone { get; set; }
public DbSet<Sites> Site { get; set; }
//public DbSet<ZoneContentModel> ZoneContent { get; set; }
//public DbSet<ZoneTypeModel> ZoneType { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Sites>().Property(r => r.SiteID)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
}
}
I think you can understand your problem and solve it reading this article: http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/