Monday 15 February 2010

c# - Saving a list of entities to the db - MVC -


I think I'm doing almost this work, but I can not understand how it will end.

Model: Public Square Location {Public Ink Placement Command {Receive; Set; } Public String SiteCode {get; Set; } Public Int Insurance (Received; Set; } Public Inc IncidentId {get; Set; }}

See model

  public list & lt; Location & gt; {Get Listings; Set; }   

Controller:

  [httpPOST] Public ActionStrust Adrecord (RecordView Model Model) {if (ModelState.IsValid) {location location; Foreign language (local place in the model) list {location = new location {PersonId = model.PersonId, SiteCode = loc.SiteCode, IncidentId = loc.IncidentId}; } {Var db = new MyEntities ()) using {db.Order.AddObject (event); Db.Location.AddObject (location); Db.Comment.AddObject (comment); Db.SaveChanges (); }   

line db.Location.AddObject (location); Getting blank. How do I get a listing from foreach, db?

You are very close!

  // Create a new list of your unit location (namespace data may not contain) var location list = new list & lt; Data Location & gt; (); Foreign language (List in model location) (var location = new data. Location {PersonId = model.PersonId, SiteCode = loc.SiteCode, IncidentId = loc.IncidentId}; locationList.Add (location);} (var db = New MyEntities {Db.Order.AddObject (event); Foreign language (various items in the space object) {db.Location.AddObject (location);} Db.Comment.AddObject (comment); db.SaveChanges () );}   

Or: Because you already have a listing on your model, instead of using

  (var db = new MyEntities () ) {Db. Order.AddObject (event); Foreign language (in model location ) (Var location = new data. Location {PersonId = model.PersonId, SiteCode = loc.SiteCode, IncidentId = loc.IncidentId}; db.Location.AddObject (location);} Db.Comment.AddObject (comment); db SaveChanges ();}    

No comments:

Post a Comment