asp.net mvc - EF 6, Code First Database table not create -
i have group user class:
[table("tblgroupuser")] public class usergroup : mytemplate { public usergroup() { users = new list<user>(); } [key] [displayname("group code"), column("groupcode", typename = "varchar")] [maxlength(20, errormessage = "group code maximum length {0}")] [required(allowemptystrings = false, errormessage = "{0} required")] public string groupcode { get; set; } [displayname("group name")] [maxlength(20, errormessage = "group code maximum length {0}")] [required(allowemptystrings = false, errormessage = "{0} required")] public string groupname { get; set; } public virtual list<user> users { get; set; } }
user class :
[table("tbluser")] public class user : mytemplate { public user() { usergroup = new usergroup(); } [key] [required(allowemptystrings = false, errormessage = "user id required , use login.")] [displayname("user id"), column("userid", typename = "varchar")] [maxlength(15, errormessage = "user id maximum length 15 characters.")] public string userid { get; set; } [required(allowemptystrings = false, errormessage = "user name required")] [maxlength(20, errormessage = "user name maximum length 20 charachters")] [displayname("user name"), column("username", typename = "varchar")] public string username { get; set; } [displayname("email"), column("email", typename = "varchar")] [datatype(datatype.emailaddress)] [maxlength(128, errormessage = "email address maximum length 128 charachters")] [required(allowemptystrings = false, errormessage = "email address required.")] public string email { get; set; } [displayname("password"), column("password", typename = "varchar")] [datatype(datatype.password)] [required(allowemptystrings = false, errormessage = "password required.")] [maxlength(128)] [minlength(6, errormessage = ("password @ least 6 charachters."))] public string password { get; set; } [displayname("user group"), column("groupcode", typename="varchar")] [required(allowemptystrings = false, errormessage = "user group required")] [maxlength(20, errormessage = "group code maximum length 20 charachters")] [foreignkey("usergroup")] public string groupcode { get; set; } [displayname("status"), column("status", typename = "tinyint")] [required(allowemptystrings = false, errormessage = "user status required")] public userstatus status { get; set; } [displayname("roles"), column("roles", typename = "varchar")] [maxlength(32)] [required(allowemptystrings = false, errormessage = "roles required.")] public string roles { get; set; } public virtual usergroup usergroup { get; set; } }
this user context :
public class userdbcontext : dbcontext { public userdbcontext() : base("dconn") { database.setinitializer<userdbcontext>(new createdatabaseifnotexists<userdbcontext>()); } public dbset<user> users { get; set; } public dbset<usergroup> usergroups { get; set; } }
if add foreign key @ groupcode or usergroup property, database table (tbluser) won't create. searched many solutions no luck. , try use fluent api , got same problem. can me please?
Comments
Post a Comment