I am trying to use a repository template to save an object using Entity Framework. I do not know how to save Navigation Properties (for example, the Account below). Can someone shed some light on this. Especially how it would be possible to set AccountId from the MVC controller all the way to the storage where it was stored.
Thanks!
--- Sample code ---
public void SavePerson(Person person) { if (person != null) { using (xxxxxxEntities bbEntities = new xxxxxxEntities()) { //see if it 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....
, . , MVC - , . , , , .
, ;
cPerson.Account = (from a in Account where a.AccountId.Equals(person.Account.AccountId) select a).FirstOrDefault();
Account , . , , , , Entity.
Source: https://habr.com/ru/post/1702404/More articles:Deleting a file using J2ME throws an IOException - javaWhat is the most pythonic way to make a related method act as a function? - functionPHP-сессия, похоже, не работает - phpHow to add NHibernate configuration file to use NHibernate.Search? - .netCSS alignment of HTML INPUT element text - htmlWCF Message Level Security - securityCan a layout manager create multiple JPanels? - javaIntegration of MooTools and jQuery - jqueryHow to email multiple addresses using MSbuild - msbuildHow to copy a file to a new location with a path length of more than 260 characters in Vista? - vb.netAll Articles