473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Linq lazy loading

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<ProductGetProductList()
{
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
Jan 10 '08 #1
2 5872
On Jan 10, 9:21 am, fredd00 <frederic.nou...@gmail.comwrote:
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<ProductGetProductList()
{
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
seems like i found some good info

http://davidhayden.com/blog/dave/arc...6/07/2983.aspx
and
http://davidhayden.com/blog/dave/arc...oundtrips.aspx
Jan 10 '08 #2
sorry i was too happy to find something those are about prefetching
and loadingOptions
good info but not exactly what i'm looking for

I want a list of products that if i ask product.category then it will
fetch the data, this after populating my list and releasing my context
object.

Jan 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Siemel Naran | last post by:
What is a good idiom for handling a lazy object? I see 2 good possibilities. Any more, any comments? Which way do people here use? (1) class Thing { public: Thing(double x, double y) :...
4
by: blackhawk | last post by:
I need to build a web page that has to potentially display a large amount of data in two grids on the same page. The HTML file with all of the formatting is about 7MB in size. This is too large...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
7
by: Andrus | last post by:
var db = new MyDb(connString); causes creation of all objects corresponding to all tables in database. Database contains 500 tables. Application accesses only few tables at a time. Creating...
1
by: 0to60 | last post by:
Let's say we have your basic Invoices and InvoiceItems table. If we load this in with LINQ: var query = from i in db.Invoices select i; When I then loop through my invoices, if I wanna...
9
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how...
4
by: Jacek Jurkowski | last post by:
Why is it so slow? I really like that queries but using DataReader i have done my task's much more faster than ising LINQ...
0
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.