Print Page | Close Window

Query Dynamic

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3505
Printed Date: 30-May-2024 at 1:24am


Topic: Query Dynamic
Posted By: giotis
Subject: Query Dynamic
Date Posted: 21-Jun-2012 at 2:45pm
what is the best method to implement a LINQ query in runtime, without limiting functionality of Cocktail.

Something like this :

string str= "EntityManager.StaffingResources
                             .Where(r => r.Id == (Guid) keyValues[0])
                             .Include(r => r.Addresses)
                             .Include(r => r.PhoneNumbers)"


IEntityQuery  query =
FromStringToEntityQuery(TempHireEntities, str);

Is this possible ?





Replies:
Posted By: mgood
Date Posted: 21-Jun-2012 at 3:44pm
That would be using the dynamic LINQ feature in DevForce. It's not quite as simple as turning a string into a query, but it's fully dynamic and lets you dynamically compose a query at runtime.
 
http://drc.ideablade.com/xwiki/bin/view/Documentation/dynamic-queries - http://drc.ideablade.com/xwiki/bin/view/Documentation/dynamic-queries


Posted By: giotis
Date Posted: 21-Jun-2012 at 4:50pm
The only reason to create queries on the fly  is only when you need to join tables without a common key or something else.
The
creation of dynamic queries by the DefForce
technique is quite difficult since I read and probably I will come
to the
ESQL
technique only when necessary.

I want to use it only for viewing. Is there any specific reason that we are forbidden to use this ?

there is any sample  - example ?


Posted By: mgood
Date Posted: 21-Jun-2012 at 5:08pm
I'm not following what you are saying. Joining tables without a common key is not a reason to create queries on the fly. As long as two entities have one or more type compatible properties you can join them statically using the join operator.
LINQ is by definition a strongly typed and static language integrated query language. That means you need to know at design time what your query is going to be and what the types are that you are querying. If you don't know that, then you are in the realm of needing to dynamically build queries at runtime. ESQL and LINQ are two different things.
 
.NET doesn't provide dyanamic LINQ out of the box, so DevForce adds this functionality. I'm not sure what you mean by forbidden to use this. Forbidden to use what?



Print Page | Close Window