I have EF model class and I've decided to extend that class with one bool
property:
class A
{
public int Id { get; set; }
public string Value { get; set; }
}
class A_DTO : A
{
public bool BoolProp { get; set; }
}
class C
{
public int Id { get; set; }
public int A_Id { get; set; }
}
Then I wrote a method, which will return that A
collection joined with some other C
collection, which contains A <=> C mapping (well, in real world example it contains some SystemId
and linq query will be joined by 2 columns) and returns A_DTO
collection:
internal IQueryable<A_DTO> MyMethod() =>
from a in dbContext.A
join c in dbContext.A_C_Mapping
on a.Id equals c.A_Id into g
from cc in gg.DefaultIfEmpty()
select new A_DTO
{
Id = a.Id,
Value = a.Value,
BoolProp = cc.A_Id != null //<- will be always true, well, that what says warning message
}
(dbContext
is my EF context object)
and of course because of cc.A_Id
is not a nullable int
the warning message will appear, saying that
"The result of expression will be always
'true'
since the value of typeint
is never equal tonull
value of typeint?
"
which is true, but in fact I get results perfectly correct, because of my left outer join return null
s when mapping missing in C
collection.
So the question: is it correct approach to do so and leave it as it is, or I need to implement it another way?