c# - One-to-One Relation EF and Seed Method -


am working on mysql connection (code first) project. have following structures in place, require one-to

public class identity {     [databasegenerated(databasegeneratedoption.identity)]     [key]     public long identityid { get; set; }     public string username { get; set; }     public string password { get; set; }     public virtual profile profile { get; set; } }    public class profile {     [databasegenerated(databasegeneratedoption.identity)]     [key]     public long profileid { get; set; }      public virtual identity identity { get; set; }      public string firstname { get; set; }  } 

i using fluent api specifying one-to-one relation follows

        modelbuilder.entity<model.user.profile>()             .haskey(e => e.profileid);           modelbuilder.entity<model.user.identity>()                     .hasrequired(s => s.profile)                     .withrequiredprincipal(a=>a.identity); 

and seed method looks follows.

        context.useridentity.addorupdate( new model.user.identity()                     {                         username = "abc",                         password = "def",                         profile = new model.user.profile                         {                             firstname = "hij"                         }                      }              );  context.savechanges(); 

however, running error when updating db via update-database commmand. following error comes up

system.invalidoperationexception: dependent property in referentialconstraint mapped store-generated column. column: 'profileid'.

could guide me ?


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -