Object references between two different object scopes are not allowed

When using ORM, should always keep in mind that only one object scope is used. The example came with the package doesn’t really explain this well. Should always declare a page_init call which declares the object scope and store it in session and try to keep using it for any business operations:

private IObjectScope cachedScope;
protected void Page_Init(object sender, EventArgs e) {
if (this.Session[“objectScope”] != null) {
cachedScope = (IObjectScope)this.Session[“objectScope”];
} else {
cachedScope = ObjectScopeProvider.GetNewObjectScope();
this.Session[“objectScope”] = cachedScope;
}
}

There’s one good example here: http://www.telerik.com/community/code-library/orm/general/best-practices-in-web-development-with-openaccess.aspx

Categories: ORM, Telerik
Tags: