0

So I have a badly formatted schema that I can't touch right now because of a lot of legacy code dependencies.

Supposed I have a table Test and it has a column IsValid that is declared type int.

I want the poco domain object to have the proper intent of IsValid as a boolean. When a query is applied in my repository, I want it to resolve correctly in the query.

.Where(o => o.IsValid == true)

should resolve to:

where isvalid = 1

Can the EntityTypeConfiguration map in this manner or will do I have to create a custom expression parser to look for special cases in the repository (which I prefer not to do)? Or is there another way (without exposing multiple properties on the domain object)?

Thanks!

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
junkyspace
  • 365
  • 4
  • 15

1 Answers1

0

You can create a query extension method to encapsulate this code:

public static IQueryable<YourEntity> ThatAreValid(this IQueryable<YourEntity> source) {
    return source.Where(x => x.IsValid == 1);
}

// usage

return entities.ThatAreValid();
Ben Foster
  • 34,340
  • 40
  • 176
  • 285