Is this use of Create() right in an Entity Framework context?

When creating an object that will be persisted to the database, and using the Create() method for this purpose, do the following snippets do the same?

Snippet 1:

Client client = new Client();
client.Name = "Jonh Doe";
database.Clients.Add(client);
database.SaveChanges();

Snippet 2:

var client = database.Clients.Create();
client.Name = "Jonh Doe";
database.SaveChanges();

Answers


According to http://msdn.microsoft.com/en-us/library/gg679504(v=vs.113).aspx they don't.

"Note that this instance is NOT added or attached to the set"

So your second snippet should be

var client = database.Clients.Create();
client.Name = "Jonh Doe";
database.Clients.Add(client);
database.SaveChanges();

Need Your Help

MarkLogic Java API batch upload files (.csv)

csv file-upload marklogic java-api

Im trying out the MarkLogic Java API and would want to bulk upload some files with the extension .csv

Android.Net.Wifi.P2p in Xamarin Monodroid?

wifi xamarin.android p2p xamarin

Does android.net.wifi.p2p planned to include to xamarin monodroid?