Change `Expression.Property` to `Expression.PropertyOrField`. ERROR: Instance property '<FIELD>' is not defined for type '<CLASS>'
See original GitHub issueI’m using LINQ TO SQL IEnumerable
I’m getting the following exception.
Instance property 'AssignedTo' is not defined for type 'IssueSearch'
It was only starting to get thrown after adding this custom IssueSearch
class with the embedded UserInfo
.
Here’s my class
public class IssueSearch
{
//<My Other Variables>
public UserInfo AssignedTo; // <-- The Important One
}
public class UserInfo
{
public string Id; // <-- The Important One
//<My Other Variables>
}
Here’s my Filter<IssueSearch>.By
. (I’ve included the Type
’s, for reference)
Filter.By(
"AssignedTo.Id", // string
Operation.In, // ExpressionBuilder.Common.Operation
[ "Id1", "Id2" ], // object {System.Collections.Generic.List<object>}
null, // object
FilterStatementConnector.And); // ExpressionBuilder.Common.FilterStatementConnector
This is how I populate the IEnumerable<IssueSearch>
using LINQ TO SQL
var query =
(
from i in d.Issues
from aT in d.Users
.Where(x => i.AssignedTo == x.Id)
.DefaultIfEmpty()
select new IssueSearch
{
//<My Other Variables>
AssignedTo = new UserInfo
{
Id = aT.Id
//<My Other Variables>
}
}
)
.Where(``Filter``); // <-- Here I Drop The Filter And The Exeption Is Thrown
Stack Trace:
at System.Linq.Expressions.Expression.Property(Expression expression, String propertyName)
at ExpressionBuilder.Helpers.BuilderHelper.GetMemberExpression(Expression param, String propertyName)
at ExpressionBuilder.Builders.FilterBuilder.GetExpression(ParameterExpression param, IFilterStatement statement, String propertyName)
at ExpressionBuilder.Builders.FilterBuilder.GetExpression[T](IFilter filter)
at ExpressionBuilder.Generics.Filter`1.op_Implicit(Filter`1 filter)
Just a bit of background (FYI): I’ve built a master page that I can override Field values, pass Classes too, etc. etc… This way I can use the same master page, make some small changes to the child page, then I have a new page that has search functionality for a set DB table.
Also, sorry if this isn’t the right way of querying the issue
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (2 by maintainers)
Top GitHub Comments
Hi Glenn,
Many thanks for taking the time to log this issue. Feedback is always welcome! 😃
Now, regarding the issue, it’s a bit strange because (from what you’ve described) it should be working. I’m pretty sure we got unit tests for this specific case.
I’m about to release a new version within the next days and it’ll fix a bug around the usage of the library with LINQ To SQL. It doesn’t seem to be exactly your case, but I’d be really glad if you could check if this issue still happens in the new version. In this meanwhile, I’ll be investigating it.
Many thanks, David
OMFG <- Pardon my French
After some more digging, I found the problem. I’m not going to tell you straight away though. First, I shall explain.
I saw the problem was with
System.Linq.Expressions.Expression.Property(Expression expression, String propertyName)
. So I pulled up the method on Microsoft’s Dev Network, here.I then placed my class, field etc. straight into that function… threw the same exception. Hmmm…
I thought, just for giggles, lets place their code in my solution. Just to make sure. Success! So, Microsoft hasn’t screwed me over. Back to, hmmm…
I then saw something, the method is called
Expression.Property
and their class consists of;Looked back at mine… WAIT A SECOND… OMFG. Mine is a
field
!!! Changed my testing method toExpression.Field
and Success (well, partial success anyway).Will you be adding support for
Expression.Field
? You can change it toExpression.PropertyOrField
[LINK], or you can see if you can detect it (although this seems pointless to me)I now have a new exception, grrr…
Message:
Stack Trace:
I can see the problem, however I use:
and (as you can see) this returns an
object
. Any help??