c# - Unable to Add Controller -
i new mvc web application development. trying add controller after adding model , dbcontext class.
but when trying controller using entity framework gives me error of
unable cast object of type 'system.data.entity.core.objects.objectcontext' 'system.data.objects.objectcontext'
i using ef-6.1.1
(latest update)
following model , context class..
public class empdetails { [key] public int id { get; set; } public string empid { get; set; } public string employeename { get; set; } } public class modelcontext : dbcontext { public dbset<empdetails> employee { get; set; } }
when trying add controller following error.
please suggest solution problem. going wrong it..
here process through adding controller
entity framework brought breaking changes between versions 5 , 6. in order go open source, moved of libraries out of band , within entityframework assembly in nuget. side effect of many of namespaces entity framework has changed:
the namespaces dbcontext , code first types have not changed. means many applications use ef 4.1 or later not need change anything.
types objectcontext in system.data.entity.dll have been moved new namespaces. means may need update using or import directives build against ef6.
the general rule namespace changes type in system.data.* moved system.data.entity.core.*. in other words, insert entity.core. after system.data. example:
system.data.entityexception => system.data.entity.core.entityexception system.data.objects.objectcontext => system.data.entity.core.objects.objectcontext system.data.objects.dataclasses.relationshipmanager => system.data.entity.core.objects.dataclasses.relationshipmanager
the reason seeing error using previous version of mvc, targeting earlier version of entity framework. scaffolding going assuming old namespaces.
you can try upgrading newest version of mvc , scaffolding work again. either or downgrade ef6 (i don't recommend this, has lot of great features). third option manually fix scaffolded code every time.
Comments
Post a Comment