.net - Entity Framework Code First Migrations thinks there is a change that shouldn't be there -
i have website , windows service both reference same project entity framework data context. each time start windows service, entity framework runs automatic migration changes 1 of database columns not null null (no other changes made). property column marked [required], , website (which points exact same version of exact same dll model), thinks database should not null column.
i tried disabling automatic migrations and, expected, service crashed because said data model had pending changes needed applied.
edit i've found out bit more info... seems happening because have both [required] , [allowhtml] attributes on property. when removed [allowhtml] attribute, didn't happen. so, question comes down to: 1) expected behavior [allowhtml] not work [required], , 2) how possible happen when web service uses code, , not when website uses code? seems web service ignores [required] when sees [allowhtml].
i'm using ef 5.
i had exact problems... pending changes had add 3 lines global.asax file on startup, looks like:
void application_start(object sender, eventargs e) { // code runs on application startup authconfig.registeropenauth(); database.setinitializer<entitycontext>(null); entitycontext context = new entitycontext(); context.database.initialize(true); }
as [allowhtml], using mvc? ...as far can tell [allowhtml] belongs system.web.mvc namespace: http://msdn.microsoft.com/en-us/library/system.web.mvc.allowhtmlattribute(v=vs.98).aspx . allowhtml intended use model binding of type. not intended form, querystring or formcollection model binding. http://forums.asp.net/t/1645209.aspx if property marked allowhtmlattribute attribute, asp.net mvc framework skips validation property during model binding, rignores [required] attribute...
the reason column changing not null null because [required] attribute overrides database schema rule allows data field empty. http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.requiredattribute.aspx
hope helps...
Comments
Post a Comment