I have done this in the past using the Dynamic Linq Library.
I am not familiar with how to do this. Do you have a sample? – Susan Jul 15 at 15:16 You have to add a reference to System.Linq.Dynamic.
Then you can write your query like this db.Restaurants. Where(myFilter). Myfilter is a string that can contain something like "cuisine_name = 'Italian'" – boca Jul 15 at 15:21 Wow, thank you!
This was a big help in simplifying my code. Regards, ~susan~ – Susan Jul 15 at 15:39.
You can compose Where conditions which are linked by a logical AND relatively easy in LINQ extension method syntax: var query = db.RESTAURANTs. Include("CITY"). Include("CUISINE").
Include("Price"); if (userHasSelectedInDDL1) query = query. Where(r => r. PropertyForDDL1 == ValueFromDDL1); if (userHasSelectedInDDL2) query = query.
Where(r => r. PropertyForDDL2 == ValueFromDDL2); if (userHasSelectedInDDL3) query = query. Where(r => r.
PropertyForDDL3 == ValueFromDDL3); if (userHasSelectedInDDL4) query = query. Where(r => r. PropertyForDDL4 == ValueFromDDL4); List result = query.ToList(); For a much more flexible solution to build queries dynamically the Dynamic LINQ Library recommended by boca is probably the better choice.
Thanks so much! I will try the Dynamic LINQ Library – Susan Jul 16 at 15:57.
When you have an application that executes structurally similar queries many times in the Entity Framework, you can frequently increase performance by compiling the query one time and executing it several times with different parameters. For example, an application might have to retrieve all the customers in a particular city; the city is specified at runtime by the user in a form. LINQ to Entities supports using compiled queries for this purpose.
The CompiledQuery class provides compilation and caching of queries for reuse. Conceptually, this class contains a CompiledQuery's Compile method with several overloads. Call the Compile method to create a new delegate to represent the compiled query.
The Compile methods, provided with a ObjectContext and parameter values, return a delegate that produces some result (such as an IQueryable instance). The query compiles once during only the first execution. The merge options set for the query at the time of the compilation cannot be changed later.
Once the query is compiled you can only supply parameters of primitive type but you cannot replace parts of the query that would change the generated SQL. The LINQ to Entities query expression that the CompiledQuery's Compile method compiles is represented by one of the generic Func delegates, such as Func. At most, the query expression can encapsulate an ObjectContext parameter, a return parameter, and 16 query parameters.
If more than 16 query parameters are required, you can create a structure whose properties represent query parameters. You can then use the properties on the structure in the query expression after you set the properties.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.