All my entities has property Id. All my tables in database has auto-generated integer identity Id as primary key.
I have generic method to Create entities.
I
This can actually be dead simple;
// Project is is object/table, no POCO here.
var newProj = new Project();
newProj.Name = "Blah project";
var db = new AppDataContextname();
db.Projects.AddObject(newProj);
// at this point, newProj.ID is NOT set
db.SaveChanges(); // record is added to db.
// now, the ID property of the Project object is set!!!
// if the last ID in that table is '25', and you have auto-increment,
// then the object's ID property will now be 26!
Console.WriteLine(newProj.ID); // will output "26"
Racked my brain on how to get the ID back for a long time until I realized that the above code works. Works in Linq-To-SQL and EF4.