score:0
As mentioned, Linq does not play well with dynamic
. Linq makes heavy use of extension methods, which much be bound at compile-time and thus you can't use dynamic
since it defers all binding to run-time.
If you have two datasets that do not have a common base type or interface, but have the same entity types (by name at least), then you'll need two overloads. You might be able to refactor part of it to improve reuse:
private void CallCustomerCodeDynamically(CustmoerEntities1 customerEntities)
{
var customerCode= from customer in customerEntities.CustomerInfoes
orderby customer.CustomerCode ascending
select customer.CustomerCode;
BindCodes(customerCode);
}
private void CallCustomerCodeDynamically(CustmoerEntities2 customerEntities)
{
var customerCode= from customer in customerEntities.CustomerInfoes
orderby customer.CustomerCode ascending
select customer.CustomerCode;
BindCodes(customerCode);
}
private void BindCodes(IEnumerable<string> customerCode)
{
ddlCustomerCode.DataSource = customerCode;
ddlCustomerCode.DataBind();
}
Source: stackoverflow.com
Related Articles
- Query expressions over source type 'dynamic' or with a join sequence of type 'dynamic' are not allowed
- LINQ TO SQL, Dynamic query with DATE type fields
- LINQ Query Field<T> with dynamic type
- How can I do an OrderBy with a dynamic string parameter order on a join query
- Linq Query with dynamic type
- Join dynamic query result with an EntitySet using Linq?
- How to do Entity Framework/Linq join in query with where clause expressions
- Dynamic linq query with join
- error :Could not find an implementation of query for source type datatable and join not found while trying to join two datatables
- Dynamic Linq query for join two tables with more than one condition(dynamically)
- The type of one of the expressions in the join clause is incorrect in Entity Framework
- Dynamic query with OR conditions in Entity Framework
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'
- Casting to a derived type in a LINQ to Entities query with Table Per Hierarchy inheritance
- How do I do a left outer join with Dynamic Linq?
- How do I most elegantly express left join with aggregate SQL as LINQ query
- LINQ select query with Anonymous type and user Defined type
- LINQ - 'The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.'
- Equivalence of query and method (lambda) syntax of a Join with Where clause
- The type of one of the expressions in the join clause is incorrect when the types are the same
- How can I build Linq query with dynamic OR statements?
- When to prefer joins expressed with SelectMany() over joins expressed with the join keyword in Linq
- join list with linq-to-sql query
- LINQ query with GROUP BY and Count(*) into Anonymous Type
- Dynamic linq query with multiple/unknown criteria
- nhibernate queryover with complex join over non-related entities
- Dynamic Where Clause over relational tables with LINQ to SQL
- linq query with dynamic predicates in where clause joined by OR
- Using LINQ Dynamic Query Library with Dictionary<string, object> and .AsQueryable()
- How can I create a dynamic LINQ query in C# with possible multiple group by clauses?
- CSV Querying in C# using LINQtoCSV
- Using LINQ calling a sproc, how can I pass a var back from a method?
- EF5: LINQ to Entities does not recognize the method System.Nullable System.Decimal Median
- how will i create multiple type id in one column database design
- Wrapping a complex linq query with a Try-Catch block and catching the correct Exceptions
- Query Table using Table Names or MetaTables - LINQ
- How to pass a string from LINQ query to ViewBag
- LINQ to SQL column has keyword as column name, how to quote/escape
- how do you loop through a List based on List contents
- Syntax to fill linq array?
- Linq error generic parameter or the query must use a nullable type
- linq to entities vs linq to objects - are they the same?
- special column convert to json
- Groupby Transform into another group
- You must add a reference to assembly mscorlib, version=4.0.0
- Populating ViewModel from multiple tables in SQL
- Attempting to obtain properties / fields from an (anonymous class) object linq is creating
- Entity Framework, Is there any performance improvement on querying at repository instead at service layer?
- Using c# GetFiles Length but only count the files with certain amount of chars in filename
- Get custom string from SQL and turn into c# date object to sort by