LINQ concat predicate OR [duplicate]












0
















This question already has an answer here:




  • Build an OR query expression progressively [duplicate]

    4 answers




Hi I'm trying to concat an linq expression
Ex: I have an List<string> where I need to read this on a loop
i need to creat a query like this



from table where (name ='someone' && id='123') || (name ='another one' && id='223') || ( name='noone' && id='456')


the follow code is what I'm working on



foreach (var item in data)
{
var name= item[4];
var cnpj = item[1];
Expression<Func<IncidentIntegration, bool>> predicated = (x => (x.EmployeesBase.name== name && x.Branch.id== id));
query = query.Union(query.Where(predicated));
}


But it's creating a query like this



from table where (name ='someone' || name ='another one' || name='noone') && ( id='223' || id='123' || id='456')


Is there someway to concat this ?










share|improve this question













marked as duplicate by Servy c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 16:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • Can your data array's structure or sample data?

    – TanvirArjel
    Dec 28 '18 at 16:31
















0
















This question already has an answer here:




  • Build an OR query expression progressively [duplicate]

    4 answers




Hi I'm trying to concat an linq expression
Ex: I have an List<string> where I need to read this on a loop
i need to creat a query like this



from table where (name ='someone' && id='123') || (name ='another one' && id='223') || ( name='noone' && id='456')


the follow code is what I'm working on



foreach (var item in data)
{
var name= item[4];
var cnpj = item[1];
Expression<Func<IncidentIntegration, bool>> predicated = (x => (x.EmployeesBase.name== name && x.Branch.id== id));
query = query.Union(query.Where(predicated));
}


But it's creating a query like this



from table where (name ='someone' || name ='another one' || name='noone') && ( id='223' || id='123' || id='456')


Is there someway to concat this ?










share|improve this question













marked as duplicate by Servy c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 16:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • Can your data array's structure or sample data?

    – TanvirArjel
    Dec 28 '18 at 16:31














0












0








0









This question already has an answer here:




  • Build an OR query expression progressively [duplicate]

    4 answers




Hi I'm trying to concat an linq expression
Ex: I have an List<string> where I need to read this on a loop
i need to creat a query like this



from table where (name ='someone' && id='123') || (name ='another one' && id='223') || ( name='noone' && id='456')


the follow code is what I'm working on



foreach (var item in data)
{
var name= item[4];
var cnpj = item[1];
Expression<Func<IncidentIntegration, bool>> predicated = (x => (x.EmployeesBase.name== name && x.Branch.id== id));
query = query.Union(query.Where(predicated));
}


But it's creating a query like this



from table where (name ='someone' || name ='another one' || name='noone') && ( id='223' || id='123' || id='456')


Is there someway to concat this ?










share|improve this question















This question already has an answer here:




  • Build an OR query expression progressively [duplicate]

    4 answers




Hi I'm trying to concat an linq expression
Ex: I have an List<string> where I need to read this on a loop
i need to creat a query like this



from table where (name ='someone' && id='123') || (name ='another one' && id='223') || ( name='noone' && id='456')


the follow code is what I'm working on



foreach (var item in data)
{
var name= item[4];
var cnpj = item[1];
Expression<Func<IncidentIntegration, bool>> predicated = (x => (x.EmployeesBase.name== name && x.Branch.id== id));
query = query.Union(query.Where(predicated));
}


But it's creating a query like this



from table where (name ='someone' || name ='another one' || name='noone') && ( id='223' || id='123' || id='456')


Is there someway to concat this ?





This question already has an answer here:




  • Build an OR query expression progressively [duplicate]

    4 answers








c# linq lambda predicate






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 28 '18 at 16:27









Marcos Brinner pikatoonsMarcos Brinner pikatoons

13312




13312




marked as duplicate by Servy c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 16:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Servy c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 16:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Can your data array's structure or sample data?

    – TanvirArjel
    Dec 28 '18 at 16:31



















  • Can your data array's structure or sample data?

    – TanvirArjel
    Dec 28 '18 at 16:31

















Can your data array's structure or sample data?

– TanvirArjel
Dec 28 '18 at 16:31





Can your data array's structure or sample data?

– TanvirArjel
Dec 28 '18 at 16:31












2 Answers
2






active

oldest

votes


















0














You can use the approach below. İt is simple and usable. Tou dont need to deal with dynamic expressions.



var result = list.Where(x => arr.Any(t => <your_condition>))





share|improve this answer


























  • you do realize, that you do not actually use x or arr at all?

    – Marco
    Dec 28 '18 at 16:35






  • 1





    I tried this way, this is creating an "and" not "or" like (name='a' && id='1') AND (name ='b' && id='2')

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:37











  • Sorry check my edit please

    – Simonare
    Dec 28 '18 at 16:41



















0














I suppose it can help you



If we consider CompleteInfos as your table then :



public class CompleteInfos
{
public int Id { get; set; }
public string Name { get; set; }

public string prop1 { get; set; }
public string prop2 { get; set; }
}
public class Info{
public int Id { get; set; }
public string Name { get; set; }
}

List<CompleteInfos> Table = new List<CompleteInfos>();
// List contains your namse and ids
List<Info> infos = new List<Info>(){
new Info(){Id = 123 , Name = "someone"},
new Info(){Id = 223 , Name = "another"},
new Info(){Id = 456 , Name = "noone"}
}
foreach(var info in infos)
{
List<CompleteInfos> selectedInfo = Table.Where(x => x.Id == info.Id || x.Name == info.Name).ToList();

//selectedInfo is the list in which you can find all item that have your desired id and name
}





share|improve this answer


























  • Well one of the reasons that I'm not using toList is because I don't want to reach the database for each line, I may have more than thousand itens so I'd like to make only one query, and I'm afraid that this may heavy the connection

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:41













  • @MarcosBrinnerpikatoons this procedure should not request the data base each time. for example you run a SELECT query on the database and then all data will be inside the RAM

    – Mohamad Armoon
    Dec 28 '18 at 16:46




















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can use the approach below. İt is simple and usable. Tou dont need to deal with dynamic expressions.



var result = list.Where(x => arr.Any(t => <your_condition>))





share|improve this answer


























  • you do realize, that you do not actually use x or arr at all?

    – Marco
    Dec 28 '18 at 16:35






  • 1





    I tried this way, this is creating an "and" not "or" like (name='a' && id='1') AND (name ='b' && id='2')

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:37











  • Sorry check my edit please

    – Simonare
    Dec 28 '18 at 16:41
















0














You can use the approach below. İt is simple and usable. Tou dont need to deal with dynamic expressions.



var result = list.Where(x => arr.Any(t => <your_condition>))





share|improve this answer


























  • you do realize, that you do not actually use x or arr at all?

    – Marco
    Dec 28 '18 at 16:35






  • 1





    I tried this way, this is creating an "and" not "or" like (name='a' && id='1') AND (name ='b' && id='2')

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:37











  • Sorry check my edit please

    – Simonare
    Dec 28 '18 at 16:41














0












0








0







You can use the approach below. İt is simple and usable. Tou dont need to deal with dynamic expressions.



var result = list.Where(x => arr.Any(t => <your_condition>))





share|improve this answer















You can use the approach below. İt is simple and usable. Tou dont need to deal with dynamic expressions.



var result = list.Where(x => arr.Any(t => <your_condition>))






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 28 '18 at 16:41

























answered Dec 28 '18 at 16:31









SimonareSimonare

7,29311435




7,29311435













  • you do realize, that you do not actually use x or arr at all?

    – Marco
    Dec 28 '18 at 16:35






  • 1





    I tried this way, this is creating an "and" not "or" like (name='a' && id='1') AND (name ='b' && id='2')

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:37











  • Sorry check my edit please

    – Simonare
    Dec 28 '18 at 16:41



















  • you do realize, that you do not actually use x or arr at all?

    – Marco
    Dec 28 '18 at 16:35






  • 1





    I tried this way, this is creating an "and" not "or" like (name='a' && id='1') AND (name ='b' && id='2')

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:37











  • Sorry check my edit please

    – Simonare
    Dec 28 '18 at 16:41

















you do realize, that you do not actually use x or arr at all?

– Marco
Dec 28 '18 at 16:35





you do realize, that you do not actually use x or arr at all?

– Marco
Dec 28 '18 at 16:35




1




1





I tried this way, this is creating an "and" not "or" like (name='a' && id='1') AND (name ='b' && id='2')

– Marcos Brinner pikatoons
Dec 28 '18 at 16:37





I tried this way, this is creating an "and" not "or" like (name='a' && id='1') AND (name ='b' && id='2')

– Marcos Brinner pikatoons
Dec 28 '18 at 16:37













Sorry check my edit please

– Simonare
Dec 28 '18 at 16:41





Sorry check my edit please

– Simonare
Dec 28 '18 at 16:41













0














I suppose it can help you



If we consider CompleteInfos as your table then :



public class CompleteInfos
{
public int Id { get; set; }
public string Name { get; set; }

public string prop1 { get; set; }
public string prop2 { get; set; }
}
public class Info{
public int Id { get; set; }
public string Name { get; set; }
}

List<CompleteInfos> Table = new List<CompleteInfos>();
// List contains your namse and ids
List<Info> infos = new List<Info>(){
new Info(){Id = 123 , Name = "someone"},
new Info(){Id = 223 , Name = "another"},
new Info(){Id = 456 , Name = "noone"}
}
foreach(var info in infos)
{
List<CompleteInfos> selectedInfo = Table.Where(x => x.Id == info.Id || x.Name == info.Name).ToList();

//selectedInfo is the list in which you can find all item that have your desired id and name
}





share|improve this answer


























  • Well one of the reasons that I'm not using toList is because I don't want to reach the database for each line, I may have more than thousand itens so I'd like to make only one query, and I'm afraid that this may heavy the connection

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:41













  • @MarcosBrinnerpikatoons this procedure should not request the data base each time. for example you run a SELECT query on the database and then all data will be inside the RAM

    – Mohamad Armoon
    Dec 28 '18 at 16:46


















0














I suppose it can help you



If we consider CompleteInfos as your table then :



public class CompleteInfos
{
public int Id { get; set; }
public string Name { get; set; }

public string prop1 { get; set; }
public string prop2 { get; set; }
}
public class Info{
public int Id { get; set; }
public string Name { get; set; }
}

List<CompleteInfos> Table = new List<CompleteInfos>();
// List contains your namse and ids
List<Info> infos = new List<Info>(){
new Info(){Id = 123 , Name = "someone"},
new Info(){Id = 223 , Name = "another"},
new Info(){Id = 456 , Name = "noone"}
}
foreach(var info in infos)
{
List<CompleteInfos> selectedInfo = Table.Where(x => x.Id == info.Id || x.Name == info.Name).ToList();

//selectedInfo is the list in which you can find all item that have your desired id and name
}





share|improve this answer


























  • Well one of the reasons that I'm not using toList is because I don't want to reach the database for each line, I may have more than thousand itens so I'd like to make only one query, and I'm afraid that this may heavy the connection

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:41













  • @MarcosBrinnerpikatoons this procedure should not request the data base each time. for example you run a SELECT query on the database and then all data will be inside the RAM

    – Mohamad Armoon
    Dec 28 '18 at 16:46
















0












0








0







I suppose it can help you



If we consider CompleteInfos as your table then :



public class CompleteInfos
{
public int Id { get; set; }
public string Name { get; set; }

public string prop1 { get; set; }
public string prop2 { get; set; }
}
public class Info{
public int Id { get; set; }
public string Name { get; set; }
}

List<CompleteInfos> Table = new List<CompleteInfos>();
// List contains your namse and ids
List<Info> infos = new List<Info>(){
new Info(){Id = 123 , Name = "someone"},
new Info(){Id = 223 , Name = "another"},
new Info(){Id = 456 , Name = "noone"}
}
foreach(var info in infos)
{
List<CompleteInfos> selectedInfo = Table.Where(x => x.Id == info.Id || x.Name == info.Name).ToList();

//selectedInfo is the list in which you can find all item that have your desired id and name
}





share|improve this answer















I suppose it can help you



If we consider CompleteInfos as your table then :



public class CompleteInfos
{
public int Id { get; set; }
public string Name { get; set; }

public string prop1 { get; set; }
public string prop2 { get; set; }
}
public class Info{
public int Id { get; set; }
public string Name { get; set; }
}

List<CompleteInfos> Table = new List<CompleteInfos>();
// List contains your namse and ids
List<Info> infos = new List<Info>(){
new Info(){Id = 123 , Name = "someone"},
new Info(){Id = 223 , Name = "another"},
new Info(){Id = 456 , Name = "noone"}
}
foreach(var info in infos)
{
List<CompleteInfos> selectedInfo = Table.Where(x => x.Id == info.Id || x.Name == info.Name).ToList();

//selectedInfo is the list in which you can find all item that have your desired id and name
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 28 '18 at 16:43

























answered Dec 28 '18 at 16:39









Mohamad ArmoonMohamad Armoon

582625




582625













  • Well one of the reasons that I'm not using toList is because I don't want to reach the database for each line, I may have more than thousand itens so I'd like to make only one query, and I'm afraid that this may heavy the connection

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:41













  • @MarcosBrinnerpikatoons this procedure should not request the data base each time. for example you run a SELECT query on the database and then all data will be inside the RAM

    – Mohamad Armoon
    Dec 28 '18 at 16:46





















  • Well one of the reasons that I'm not using toList is because I don't want to reach the database for each line, I may have more than thousand itens so I'd like to make only one query, and I'm afraid that this may heavy the connection

    – Marcos Brinner pikatoons
    Dec 28 '18 at 16:41













  • @MarcosBrinnerpikatoons this procedure should not request the data base each time. for example you run a SELECT query on the database and then all data will be inside the RAM

    – Mohamad Armoon
    Dec 28 '18 at 16:46



















Well one of the reasons that I'm not using toList is because I don't want to reach the database for each line, I may have more than thousand itens so I'd like to make only one query, and I'm afraid that this may heavy the connection

– Marcos Brinner pikatoons
Dec 28 '18 at 16:41







Well one of the reasons that I'm not using toList is because I don't want to reach the database for each line, I may have more than thousand itens so I'd like to make only one query, and I'm afraid that this may heavy the connection

– Marcos Brinner pikatoons
Dec 28 '18 at 16:41















@MarcosBrinnerpikatoons this procedure should not request the data base each time. for example you run a SELECT query on the database and then all data will be inside the RAM

– Mohamad Armoon
Dec 28 '18 at 16:46







@MarcosBrinnerpikatoons this procedure should not request the data base each time. for example you run a SELECT query on the database and then all data will be inside the RAM

– Mohamad Armoon
Dec 28 '18 at 16:46





Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas