Code First: UserData and User tables -


i have problems code first , code migrations.

i have user class , userdata class (with optional information first/last name), when try run 'add-migration' or 'update-database' command, several errors.

i have created user class:

public class user {     public int id { get; set; }     public string username { get; set; }     public string emailaddress { get; set; }     public datetime dateofbirth { get; set; }      public userdata userdata { get; set; }     public int userdataid { get; set; } } 

and userdata class:

public class userdata {     public int id { get; set; }     public string firstname { get; set; }     public string lastname { get; set; }     public string city { get; set; }     public string country { get; set; } } 

with setup error:

multiple identity columns specified table 'users'. 1 identity column per table allowed.

when trying run 'update-database' (the 'add-migration' command runs fine).

i tried add public user user { get; set; } , public int userid { get; set; } userdata.cs, error 'add-migration' command:

unable determine principal end of association between types 'userdata' , 'user'. principal end of association must explicitly configured using either relationship fluent api or data annotations

any idea how fix this?

thanks in advance.

remove userdataid user class, there no need it. also, make public virtual userdata userdata { get; set; } ef populate when access firstname, etc.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -