F
fredd00
Hi,
i'm trying to use lazy loading with Linq to sql and related objects
seems like you can only call the child object if the context is still
open, this is not real lazy loading.
here is my actual implementation
my class product has a categories collection (using a one-to-many
relation in .dbml)
I bind a product list to a repeater that need to display
product.category.name (with should be lazy loaded)
-> when I use a linqdataobject as the repeater source , i get the
error that the context is closed
-> when I use a facade that returns a list of products - the
categories are not early nor lazy loaded
public static List<Product> GetProductList()
{
using(context ctx = new context())
{
var list = from p in ctx.products
join c in ctx.categories on p.categoryid equals c.id
select p;
return list.ToList<Product>();
}
}
-> when I use
using (context ctx = new context())
{
repeater.DataSource = from p in ctx.products
repeater.DataBind();
}
this works since the context is open but i don't want to do it in my
web page and this is not using a LinqDataObject
I want to simply call a method that returns a list of product with
lazy loading of the category list.
how can i do this?
thanks
i'm trying to use lazy loading with Linq to sql and related objects
seems like you can only call the child object if the context is still
open, this is not real lazy loading.
here is my actual implementation
my class product has a categories collection (using a one-to-many
relation in .dbml)
I bind a product list to a repeater that need to display
product.category.name (with should be lazy loaded)
-> when I use a linqdataobject as the repeater source , i get the
error that the context is closed
-> when I use a facade that returns a list of products - the
categories are not early nor lazy loaded
public static List<Product> GetProductList()
{
using(context ctx = new context())
{
var list = from p in ctx.products
join c in ctx.categories on p.categoryid equals c.id
select p;
return list.ToList<Product>();
}
}
-> when I use
using (context ctx = new context())
{
repeater.DataSource = from p in ctx.products
repeater.DataBind();
}
this works since the context is open but i don't want to do it in my
web page and this is not using a LinqDataObject
I want to simply call a method that returns a list of product with
lazy loading of the category list.
how can i do this?
thanks