I have a table from which I want a value like this. I need price info w.r.t. states and vendor, for example, I want to calculate the price for a state, my table has data like either vendor has a price or default price.
So if I look for VendorA in NY I should get 2000. And if I look for VendorA in LA it will give me 1500. I can get this by
public long GetPrice(string State, string Vendor){
var value = this.context.table.FirstOrDefault(a=>a.vendor == Vendor && a.state == State);
if(value == null){
value = this.context.table.FirstOrDefault(a=>a.vendor == null && a.state == State)?.Price;
}
}
GetPrice("NY","VendorA"); //This should give me 2000.
GetPrice("LA","VendorA"); // This should give me 1500
Please suggest is there is some more optimized way, means Can I get in a single DB call.