c# - Saving an entity graph using entity framework -


I am writing data access layers using EntityFramework 6. What should I do when I save the code with SaveChanges () DbContext, it will save the unit with the set of relevant institutions connected through navigation properties. The following is the simple code that I am trying to do.

  public class customer {get public long id { Set; } Public string name {get; Set; } Public Virtual IEnumberable & lt; PhoneNumber & gt; { get; Set; }} Set the public category phone number {public long ID}; } Public string number {get; Set; }} Public Class Sample Contact: DBCOntax {Public Virtual DBSet and LT; Customers & gt; Customer {Received; Set; } Public Virtual DbSet & lt; PhoneNumber & gt; Phone number (get); Set; }} Using (var context = new sample syntax ()) {var customer = new customer {id = 1, name = "John"}; Customer Phone number = new phone number [] {new phone number {id = 1, number = "1.111.1111111"}, new phone number {id = 2, number = "1.111.1111112"}} references. Customer Add (customer); Context.SaveChanges (); }  

The above code saves the customer in the customer table but the phone number does not save anything in the table. Strange but found a solution The above code requires a little change in this work. The follow-up revisions are:

  // In the customer class, changes in the following line: public virtual IEnumberable  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -