.net - Entity Framework load entity from parameterized Constructor -


i upgrading 1 of existing projects dal entity framework. in leagcy dal hav consturctors e.g.

public class user{     public user(){}     // constructor loads data database userid found    public user(int userid){}   } 

so how can implement in ef i.e. when pass userid in parameterized constructor should populate user entity database ?

when pass userid in parameterized constructor should populate user entity

looks turning entity framework requires paradigm shift. used active record or similar. when work ef important notion entities (i.e. classes user) persistence ignorant.

the context responsible materializing entity objects database, tracking changes , saving changes. entities not involved in this.

so in case you'd no longer user by

var user = new user(1); 

but by

using(var context = new mycontext()) {     var user = context.users.find(1);     // in objectcontext: context.users.single(u => u.userid == 1) } 

it looks more elaborate way, user simple poco (if work code first). there's nothing inside of legacy dal must have had.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -