Reputation: 158
I have 2 database fields and there is need to filter results based on those values.
As an example customers max storage places and storage places in use. To determine if someone is using more space I would like to make like this.
var temp = db.Storege.Where(o => (o.max_storage_places - o.places_in_use) < 0).ToList()
But this is not working. Is this possible or should I use different approach?
EDIT:
Database is MySQL and it is used trough Entity Framework. The datatype for both fields are INT values in database.
I tested that following version is working which was suggested
var temp = db.Storege.Where(o => o.max_storage_places < o.places_in_use).ToList()
ROOT CAUSE:
I was investigating this problem more deeply and found out that this is MySQL related issue. The fields were for some reason "Unsigned INT" so for database didn't understand the negative values in calculation.
Both cases will work
Upvotes: 0
Views: 60
Reputation: 65870
Yes,you can do it.But you have to use ToList()
to fetch the records from the database.
var temp = db.Storege.Where(o => (o.max_storage_palces - o.places_in_use) < 0).ToList();
OR
var temp = db.Storege.Where(o => (o.max_storage_palces < o.places_in_use ).ToList();
Upvotes: 2