c# - Query expressions over source type 'dynamic' or with a join sequence of type 'dynamic' are not allowed -


i passing entity dynamically parameter. but, getting exception while using linq same entity object.

error:query expressions on source type 'dynamic' or join sequence of type 'dynamic' not allowed

private void callcustomercodedynamically(dynamic customerentities) {     var customercode= customer in customerentities.customerinfoes                    orderby customer.customercode ascending                    select customer.customercode;     ddlcustomercode.datasource = customercode;     ddlcustomercode.databind(); } 

please give me suggestion resolve this.

as mentioned, linq not play dynamic. linq makes heavy use of extension methods, bound @ compile-time , can't use dynamic since defers binding run-time.

if have 2 datasets not have common base type or interface, have same entity types (by name @ least), you'll need 2 overloads. might able refactor part of improve reuse:

private void callcustomercodedynamically(custmoerentities1 customerentities) {     var customercode= customer in customerentities.customerinfoes                    orderby customer.customercode ascending                    select customer.customercode;      bindcodes(customercode); }   private void callcustomercodedynamically(custmoerentities2 customerentities) {     var customercode= customer in customerentities.customerinfoes                    orderby customer.customercode ascending                    select customer.customercode;      bindcodes(customercode); }  private void bindcodes(ienumerable<string> customercode) {     ddlcustomercode.datasource = customercode;     ddlcustomercode.databind(); } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -