简体   繁体   中英

How to pass one or more arguments in Lambda expression in ASP.net

var itemInventoryUpdate2 = db.ItemInventoryDatas
     .Single(items => items.ItemId == item.ItemId );

Hi How can I convert above code so that I can pass to multiple arguments like it will select not just for Item Id but also for the location Id.

use AND operator.

  var itemInventoryUpdate2 = db.ItemInventoryDatas.Single(items => items.ItemId == item.ItemId && items.LocationId == item.LocationId);

You can use boolean logical operators inside lambdas:

var itemInventoryUpdate2 = db.ItemInventoryDatas
     .Single(items => items.ItemId == item.ItemId && items.LocationId == item.LocationId);

Also if you want to concatenate multiple AND conditions you can specify multiple Where clauses:

var itemInventoryUpdate2 = db.ItemInventoryDatas
     .Where(items => items.ItemId == item.ItemId)
     .Where(items => items.LocationId == item.LocationId)
     .Single();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM