C#2010 An expression tree may not contain a dynamic operation
-
Thursday, May 28, 2009 9:35 PMI understand the text of the error and what is occurring in my code - I have a dynamic type defined as a parameter to a method. I try to use that type within a Linq statemente.g. -var query =from row in Db.SomeTablewhere row.SomeField == dynamicType.SomePropertyselect rowAny idea on how to code around this?For background, I am trying to migrate an app to .NET v4 from 'some other language' and do not want to rearchitect the app during the conversion (that's v2<g>).
All Replies
-
Thursday, May 28, 2009 9:37 PMModeratorCould you store the value in a temp value just above the query?
string value = dynamicType.SomeProperty
var query =
from row in Db.SomeTable
where row.SomeField == value
select row
David Morton - http://blog.davemorton.net/ - @davidmmorton -
Thursday, May 28, 2009 9:42 PMI would have a huge amount of variables as the methods I am looking at have dozens of properties being used.
e.g. -
object column1 = row.SomeField1
object column2 = row.SomeField2
object column3 = row.SomeField3
object column4 = row.SomeField4
...
And then you need to understand and try to cast to the appropriate type - worse because many of these are complex objects, not a simple int. My example probably should have been something more like:
var query =from row in Db.SomeTablewhere row.SomeField == dynamicType.SomeInnerClass.SomePropertyselect row

