Explicit construction of entity type in query is not allowed

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
crazypit
Posts: 163
Joined: Wed 15 Apr 2009 08:43

Explicit construction of entity type in query is not allowed

Post by crazypit » Thu 16 Jul 2009 11:38

Hello,

I query 2 DB Entities, Customer & CustomerInfo using DotConnect for Oracle. At the end of my query, i need to create an Entity which is not bound to a DB Table and is made by me, SearchedCustomer. The query is this:

IQueryable result = query.Select(a => new SearchedCustomer
{
Id = (long) a.Customer.Id,
Code = a.Customer.Code,
AccountName = a.CustomerInfo.AccName,
TaxRegNo = a.CustomerInfo.TaxRegno,
IdCardNo = a.CustomerInfo.Identity,
Balance = (decimal) a.Customer.Balance,
BalanceAge=(int)a.Customer.BalAge,Status=a.Customer.Status});

List objCustomers = result.ToList();

Last line raises an error :
{"Explicit construction of entity type 'ExrayEntities.SearchedCustomer' in query is not allowed."}

Funny thing is that using version 5.20.33 of DotConnect for ORacle, everything worked ok. Using the latest version 5.25.37, i get the aforementioned error.

Do i need to change something in the way i design things?

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

Post by AndreyR » Thu 16 Jul 2009 12:10

Please check that the entity you have created in the query (SearchedCustomer) does not have the
Table attribute in the generated code.
We have denied the creation of the Table entities because of possible synchronization issues,
just in the way Microsoft does in LINQ to SQL.

crazypit
Posts: 163
Joined: Wed 15 Apr 2009 08:43

Post by crazypit » Thu 16 Jul 2009 13:18

Yes, that worked. Nevertheless, if i try to generate the SearchCustomer entity through Entity Developer, a Table attribute is inserted with an empty name even if i don't specify a Source for it. What is the point of this? Wouldn't be better for the Entity Developer not to generate a Table attribute at all? This way, all the unbounded entities could be properly maintained through it.

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

Post by AndreyR » Thu 16 Jul 2009 14:11

Thank you for the suggestion, we are already working on it.
The entities with empty Source propery will not have the Table attribute.
As a temporary workaround, I recommend you to move the code associated with the SearchCustomer entity
to the DataContext.cs class (it is not affected by model changes).

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

Post by AndreyR » Fri 23 Oct 2009 08:42

The requested functionality is implemented in the upcoming Beta build of Entity Developer.

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

Post by AndreyR » Mon 02 Nov 2009 08:23

The Beta build is available for download.

Post Reply