Print Page | Close Window

query inherited entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2198
Printed Date: 24-Jun-2026 at 1:33am


Topic: query inherited entities
Posted By: sky40627
Subject: query inherited entities
Date Posted: 28-Sep-2010 at 7:41am
when performing this query
 
 BindableList<Employee> _bl = new BindableList<Employee>();
            BindingSource _bs = new BindingSource();
            _bs.DataSource = _bl;
            IEntityQuery<Employee> qry = (IEntityQuery<Employee>)_entityManager.BasePersons
                .Include(Employee.PathFor(b => b.Address))
                .Include(Employee.PathFor(b => b.Address.Country))
                .Where(b => b.Name.Contains(pValue))
                .OfType<Employee>()
                ;
            _bl.ReplaceRange(qry);
 
where Employees are inherited from BasePersons
 
the sql query does not perform the include (there is no join in the sql statement) so the application ends up fetching all Addresses one by one
 
when doing this query for all basepersons then it is ok
 
What is the problem here ?



Replies:
Posted By: sky40627
Date Posted: 29-Sep-2010 at 1:57am
BindableList<Employee> _bl = new BindableList<Employee>();
            BindingSource _bs = new BindingSource();
            _bs.DataSource = _bl;
            IEntityQuery<Employee> qry = (IEntityQuery<Employee>)_entityManager.BasePersons
                .Include(Employee.PathFor(b => b.Address))
                .Include(Employee.PathFor(b => b.Address.Country))
                .Where(b => b.Name.Contains(pValue))
                                ;
            _bl.ReplaceRange(qry.ToList().OfType<Employee>()
);
 
I changed to this and it works fine, why ?
 
Can somebody explain this to me ?


Posted By: sky40627
Date Posted: 29-Sep-2010 at 4:13am
I have yet another question
 
The specified type member 'Name' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
 
is the error I get when doing this
 
BindableList<Customer> _bl = new BindableList<Customer>();
BindingSource _bs = new BindingSource();
_bs.DataSource = _bl;

       var qry =_entityManager.Countries
==>            .Where(c => c.Name.Contains(pValue));
 
_bl.ReplaceRange(qry.ToList());
 
 
what is the reason for this ? I cannot use "Name" as an entity property ?


Posted By: sky40627
Date Posted: 29-Sep-2010 at 4:24am
you can ignore last question, Name was not a database Property
 
 


Posted By: DenisK
Date Posted: 30-Sep-2010 at 10:48am
Hi sky40627;

The reason is that the line

query.ToList();

performs an immediate execution of the query.

This is true for other clauses such as First(), FirstOrNullEntity(), FirstOrDefault(), etc.



Print Page | Close Window