c# - How to set custom name of ICollection property in automatically generated POCO entity, using Entity Framework -



c# - How to set custom name of ICollection property in automatically generated POCO entity, using Entity Framework -

let’s there 2 tables in database:

user int userid string name task int taskid string description int taskcreatorid int taskassigneeid

and 2 foreign keys defined between task , user: taskcreatorid – userid , taskassigneeid - userid

i have database, , utilize "database first" approach. using code generation in entity framework, 2 poco classes automatically created:

user.cs

public int userid public string name public icollection<task> tasks public icollection<task> tasks1

task.cs

public int taskid public string description public int taskcreatorid public int taskassigneeid public user user public user user1

in order have meaningful entities, have change:

public icollection<task> tasks --> public icollection<task> createdtasks public icollection<task> tasks1 --> public icollection<task> assignedtaska

and

public user user --> public user taskcreator public user user1 --> public user taskassignee

if go model.edmx , create changes in model browser –> associations , set needed mapping, overwritten after first update database.

how this?

are familiar view models? can create classes represent entities in different ways suite needs.

so create new folder called viewmodels, create new class appropriate name, , add together members there - taskcreator, taskassignee, etc. common, standard design pattern.

you can search viewmodel, or here's started...

http://www.markwithall.com/programming/2013/03/01/worlds-simplest-csharp-wpf-mvvm-example.html

c# entity-framework poco ef-database-first

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -