D
D
Dmitry Gavrilenko2015-12-16 11:48:53
.NET
Dmitry Gavrilenko, 2015-12-16 11:48:53

An expression tree cannot contain a dynamic operation?

Hello. The integration of one of the systems with 1C is being written. Connection via Com, all variables are dynamic. An incomprehensible thing began to happen. Rows come from 1C, the fields of which contain a link to objects. I take the field I need, and pass it to the function receiving dynamic. Then the dynamic variable is parsed into its components and in List.Find( ... )
the following check is made:
Find(p => p .1CCode == p rod.Parent.Code.ToString()).FirstOrDefault()
PS: Checking for " Code" is there a 1C object in the sheet.
When starting the execution, the compiler gives an error 2 times: The expression tree cannot contain a dynamic operation and points to the places that I selected.
What's the fak?
How is this snippet different from Where(t => t.1CCode == priceType.Code.ToString()).FirstOrDefault() which works flawlessly?
UPD: Initially, all searches in the sheet were carried out through FindAll().Where().FoD(), which I think is not correct if you need to get one object, deciding to search further through Find().FoD() got an error. Changed my Find().FoD() to FindAll().Where().FoD() and got working code lol...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mykola Dzedzinskyi, 2015-12-16
@Maddox

Firstly, it is not logical to use Find(...условие...).FirstOrDefault(), because Find can throw ArgumentNullException if there is no such element that will satisfy the condition, and if it does, it will not return a collection but an object.
Use better FirstOrDefault(...условие...), it will return null in this case.

S
Stanislav Makarov, 2015-12-16
@Nipheris

The compiler complains that somewhere in your lambdas it encountered dynamic, and of course it cannot compile it into an expression tree. Most likely p was dynamic but t was not. Indicate in the question the specific types of containers for which you did Find and Where, maybe the situation will become clearer (and at the same time, what interfaces they implement - IEnumerable<T>or IQueryable<T>).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question