3
我试图使用存储库模式来保存使用实体框架的实体。我不清楚如何保存导航属性(如下面的帐户)。任何人都可以对此有所了解。尤其是如何将AccountId从MVC控制器一直设置到存储它的存储库。如何在实体框架中保存导航属性
谢谢!
---示例代码---
public void SavePerson(Person person)
{
if (person != null)
{
using (xxxxxxEntities bbEntities = new xxxxxxEntities())
{
//see if it's in the db
Person cPerson;
ObjectQuery<Person> persons = bbEntities.Person;
cPerson = (from p in persons
where p.PersonId == person.PersonId
select p).FirstOrDefault() ?? new Person();
//synch it
cPerson.Account.AccountId = person.Account.AccountId; //<=== ????
cPerson.Active = person.Active;
cPerson.BirthDay = person.BirthDay;
cPerson.BirthMonth = person.BirthMonth;
cPerson.BirthYear = person.BirthYear;
cPerson.CellPhone = person.CellPhone;
cPerson.CreatedBy = person.CreatedBy;
cPerson.CScore = person.CScore;
Etc....