Using Entity Framework to compare two distinct kinds

c# entity-framework linq linq-to-entities

Question

Let's say I have aPosts field in a tableOwner of a kindPerson (that has a field)Name ).

I'm attempting to make this abbreviation effective:

from p in Posts where p.Author == "SomeNameAsString" select p;

It would need me to compare objects of the same kind.Person with astring .

I attempted to bypass.Equals Despite adding and to override operators == and!=, the error "DbComparisonExpression needs arguments with similar types" still occurs.

Is it possible to compare two distinct types in Entity Framework?

1
0
1/24/2012 10:05:33 AM

Accepted Answer

When EF attempts to convert your query into SQL, it doesn't seem to take your type conversion operators into consideration. Instead, just use this simple phrase:

from p in Posts where p.Author.Name == "SomeNameAsString" select p;
5
1/24/2012 10:06:24 AM

Popular Answer

Have you ever?

 from p in Posts where p.Author.Name == "SomeNameAsString" select p; 

(if Name is a house onAuthor )



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow