This question is locked. New answers and comments are not allowed.
I have an Object called "Contact" (name, lastname ect.) This object includes a country object. On my first web form I collect the users data and put it into the objects:
Contact myContact = new Contact();
int cid =int.Parse(rcb_country.SelectedValue.ToString());
IObjectScope scope1 = ObjectScopeProvider1.GetNewObjectScope();
var cselected = from a in scope1.Extent<Country>()
where a.CountryID == cid
select a;
scope1.Transaction.Begin();
foreach (Country coun in cselected)
myContact.Country = coun;
scope1.Transaction.Commit();
Ok....this works fine.
On my last page I try to insert the contact into my database, like this:
if (cb_agb.Checked)
{
IObjectScope scope2 = ObjectScopeProvider1.GetNewObjectScope();
try
{
scope2.Transaction.Begin();
scope2.Add(myContact);
scope2.Transaction.Commit();
}
catch (Exception ex)
{
scope2.Transaction.Rollback();
}
}
Now I get an error: object references between two different objects scopes are not allowed.........the object ...country is already managed
What can it be?
Contact myContact = new Contact();
int cid =int.Parse(rcb_country.SelectedValue.ToString());
IObjectScope scope1 = ObjectScopeProvider1.GetNewObjectScope();
var cselected = from a in scope1.Extent<Country>()
where a.CountryID == cid
select a;
scope1.Transaction.Begin();
foreach (Country coun in cselected)
myContact.Country = coun;
scope1.Transaction.Commit();
Ok....this works fine.
On my last page I try to insert the contact into my database, like this:
if (cb_agb.Checked)
{
IObjectScope scope2 = ObjectScopeProvider1.GetNewObjectScope();
try
{
scope2.Transaction.Begin();
scope2.Add(myContact);
scope2.Transaction.Commit();
}
catch (Exception ex)
{
scope2.Transaction.Rollback();
}
}
Now I get an error: object references between two different objects scopes are not allowed.........the object ...country is already managed
What can it be?