How to use IN Operator inside Where Condition in Linq - entity-framework

I need a help to how to use IN Operator in linq ,
Here is my Code:
achieved =grouped.Key.SMCode=="HETAL1"?
grouped.AsEnumerable().Where(x => (x.SalesManCode=="HETAL1"||x.SalesManCode=="BAIJU") &&
x.OrderType == "Sales Invoice" && x.IsFromService==true).Sum(m => m.OrderValue):0
Here i need the value for both Salesmancode baiju and hetal1 ,but now i got value only for hetal1
i dont know , how to use IN operator in linq
pls help me to get the values of both salesmancode

Please try as shown below.
achieved =(grouped.Key.SMCode=="HETAL1" || grouped.Key.SMCode=="BAIJU") ?
grouped.AsEnumerable().Where(x => (x.SalesManCode=="HETAL1"||x.SalesManCode=="BAIJU") &&
x.OrderType == "Sales Invoice" && x.IsFromService==true).Sum(m => m.OrderValue):0

Related

EF Core: The LINQ expression could not be translated - Net Core 3.1

I am trying to implement a query to find all Conditions in each Site that match the assigning user's conditions and delete them - excluding the ones that don't match.
var savedPartnerConditions = eipDbContext.EIP_User_Partner_Condition.Where(savedCondition => savedCondition.EIP_User_Partner_Id == savedPartner.EIP_User_Partner_Id && existingUser.CurrentUserConditions.Any(condition => condition.Code == savedCondition.Code));
eipDbContext.EIP_User_Partner_Condition.RemoveRange(savedPartnerConditions);
But the query cannot be translated resulting in the following error:
.Any(condition => condition.Code == e.Code))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync()
How can I contruct the query to fix the error?
I was able to fix this with the following code that seems to work:
var selectionResultSet = eipDbContext2.EIP_User_Partner_Condition.Where(savedCondition => savedCondition.EIP_User_Partner_Id == savedPartner.EIP_User_Partner_Id).ToList();
var savedPartnerConditions = selectionResultSet
.AsEnumerable()
.Where (savedCondition => (existingUser.CurrentUserConditions.Any(condition => condition.Code == savedCondition.Code)));
eipDbContext3.EIP_User_Partner_Condition.RemoveRange(savedPartnerConditions);

Linq where clause with nullable parameters

I'm trying to do a linq query which might have nullable params.
This is my linq call
listOfControlsVM = db.Controls.Where((status == null || s.Status.Description == status) && (impact == null || s.Impact == impact)).ToList();
Now either status or impact can be nullable params (I have two more but I removed them from the example). With the approach I have the query doesn't return the correct set of results.
I want to know if there is other better approach to work with nullable params in linq. For example if status or impact have value include them in the conditions, otherwise skip them.
There is a HasValue to check null value on nullable variable instead of null.
listOfControlsVM = db.Controls.Where((!status.HasValue || s.Status.Description == status) && (!impact.HasValue || s.Impact == impact)).ToList();
I hope this will help you out :)

Drool DRL contains

This my When condition
$cla : cashliquidassets(
entity == "AU001",
asset_liability_indicator == "A",
product_group.contains('Loans','Bankofindia'),
product.contains("DS"),
counterparty_resident_indicator == "AU",
counterparty_type.contains("DS"),
related_entity == "Y"
)
I am getting an error at
Unable to Analyse Expression product_group.contains("Loans","Bankofindia")
Any Suggestions
Without your class model is hard to tell, but assuming that cashliquidassets.product_group is a String, you are trying to use an unexisting method String.contains(String, String).
One option would be to use an OR or and AND between 2 contains:
...
(product_group.contains('Loans') || product_group.contains('Bankofindia')),
...
or
...
product_group.contains('Loans'),
product_group.contains('Bankofindia'),
...
Another option could be to use the matches operator with a regular expression.
Hope it helps,

Process interval tick based on condition RXJS

I have the following interval in my code, where I want to run some logic, however I need to do some queries before knowing if I can process the logic developed or not:
This is my observable:
const interval$ = Observable.interval(120000).startWith(0);
I need to map to this observable and only let it process if the return from a service call is not equal 1:
documentRepository.getProcedureLock().then(data => {
if (data !== null && data !=== '1') {
I have tried many things without success... the logic that process my interval is a .mergeMap and I don't have enough experience with it...can u guys help out?
See if that's what u looking for
Rx.Observable.fromPromise(documentRepository.getProcedureLock()).flatMap(data
=> {
if (data !== null && data !=== '1') return interval$
// i assume you want data if condition not met
return Rx.Observable.of(data)
}).subscribe(console.log)

scala lift - filterNot with multiple arguments

I have the following filter on a List:
messages = messages.filterNot(m => m.room == room)
What I'm trying to do is have multiple arguments so I can match all items that have the same room ID and the same data value, so something like:
messages = messages.filterNot(m => m.room == room, m.data == data)
This doesnt work of course, is there a way I can do this?
Thanks in advance, any help much appreciated :)
You can deal with it
straightforward
messages.filterNot(m => m.room == room && m.data == data)
chaining filters
messages.filterNot(_.room == room).filterNot(_.data == data)
using WithFilter which applies restrictions on original collection instead of creating intermediate ones
messages.withFilter(_.room != room).withFilter(_.data != data) map identity