how to skip object when submitchanges in ado.net
I'm using ado.net entity data model. I have 2 object User
Organization
My problem is
User user=new User();
...
Organization org=new Organization()
db.Organizations.AddObject(org);
db.SubmitChanges(); // Problem is here. Because datacontext try to save user object. user object开发者_运维技巧 some field is empty. I don't need to save user here. How to skip user object from submitchanges
user.organization=org;
db.SubmitChanges(); // I need to save user object here
You need a using statement to scope out your data context.
Not exactly sure what you are trying to achieve, but something like this?
Organization org=new Organization();
User user = new User();
using (var ctx = new YourContext())
{
ctx.Organizations.InsertOnSubmit(org);
ctx.SubmitChanges();
user.Organization = org;
}
using (var newCtx = new YourContext())
{
// code to persist user
}
精彩评论