How to explicitly specify which objects to load from DB?

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
[email protected]
Posts: 43
Joined: Wed 17 Sep 2008 11:31

How to explicitly specify which objects to load from DB?

Post by [email protected] » Fri 27 Mar 2009 10:30

Hello

I am desperate. I have a Countries table and a related CountryTranslations table with the translations of each country name. Now I'd like to fetch all countries from the Countries table but fetch only the English translations in the related CountryTranslations table. In Microsoft LINQ this is possible with the LoadWith And AssociateWith DataLoadOptions. What's the workaround in Devart?

I was trying something like this:

Code: Select all

var recordSet = from c in PPGlobal.Countries
				join ct in PPGlobal.CountryTranslations on c.CountryId equals ct.CountryId
				join l in PPGlobal.Languages on ct.LanguageId equals l.LanguageId
				where l.Abbreviation.ToLower() == "en"
				select new { CountryTranslation = ct, Country = c };


List countries = new List();
foreach (var record in recordSet)
{
	record.Country.CountryTranslations.Add(record.CountryTranslation);
	countries.Add(record.Country);
}
But because of deferred loading, each Country object will have all it's related translations in the CountryTranslation property.

How is it possible to only fill the releated data due to a condition (for example with a lambda expression)?

I don't want to reload each country's translation with a separate sql query as done with the automatic deferred loading. I want to fetch the data all at once within a single query (joined) like above.

Please help! Thank you very much
Thomas
________
Weed
Last edited by [email protected] on Thu 17 Feb 2011 05:20, edited 1 time in total.

[email protected]
Posts: 43
Joined: Wed 17 Sep 2008 11:31

Post by [email protected] » Fri 27 Mar 2009 11:05

The code above would work if I could disable the deferred loading. But unfortunately the following line...

Code: Select all

PPGlobal.DeferredLoadingEnabled = false;
does not work either :-(
________
Vaporizer affiliate program
Last edited by [email protected] on Thu 17 Feb 2011 05:20, edited 1 time in total.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 27 Mar 2009 13:38

For filtering entities in a way you described you should use DataLoadOptions.AssociateWith() method.
Support for this scenario will be available in the next Beta build of dotConnects.
We will investigate the problem with DeferredLoadingEnabled.

[email protected]
Posts: 43
Joined: Wed 17 Sep 2008 11:31

Post by [email protected] » Mon 30 Mar 2009 09:09

Hello.

Thank you for your answer. Do you have already any idea when the next beta will be available?

When do you expect the first results about the problem with DeferredLoadingEnabled?
________
TWO AND A HALF MEN FORUMS
Last edited by [email protected] on Thu 17 Feb 2011 05:20, edited 1 time in total.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 31 Mar 2009 09:12

We plan to release new Beta build next week.
The DeferredLoadingEnabled functionality will be added in this Beta build.

Post Reply