Using Linq to EF to search using a array as search parameter
I have already read and tried several links from here but none of them are quite a good fit.
I have a query that currently is searching using a number of or "||" clauses that I need to replace with a dynamicly assigned list. It can be an array or a List<>
My current code:
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Created_By == null && c.Company_No == 1 &&
(c.Customer_No == 228 || c.Customer_No == 227) &&
(c.Branch_Id == "MEM" || c.Branch_Id == "TXK" || c.Branch_Id == "TUP" || c.Branch_Id == "LIT")
&&
c.Shipment_Type == "D" &&
(c.Datetime_Created > dateToSearch || c.Datetime_Updated > dateToSearch) &&
rh.Company_No == 1 &&
rh.Route_Date >= routeDateToSearch
orderby c.Unique_Id_No descending
select new
{
c.Datetime_Updated,
c.Datetime_Created,
I need something like this (psedocode)
string brancheSearchList = new string "TUP", "LIT" ;
List<string> branchList = new List<string>();
branchList.Add("TUP");
branchList.Add("LIT")
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Created_By == null && c.Company_No == 1 &&
(c.Customer_No == 228 || c.Customer_No == 227) &&
(c.Branch_Id IS IN branchesSearchList)
c# entity-framework linq
add a comment |
I have already read and tried several links from here but none of them are quite a good fit.
I have a query that currently is searching using a number of or "||" clauses that I need to replace with a dynamicly assigned list. It can be an array or a List<>
My current code:
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Created_By == null && c.Company_No == 1 &&
(c.Customer_No == 228 || c.Customer_No == 227) &&
(c.Branch_Id == "MEM" || c.Branch_Id == "TXK" || c.Branch_Id == "TUP" || c.Branch_Id == "LIT")
&&
c.Shipment_Type == "D" &&
(c.Datetime_Created > dateToSearch || c.Datetime_Updated > dateToSearch) &&
rh.Company_No == 1 &&
rh.Route_Date >= routeDateToSearch
orderby c.Unique_Id_No descending
select new
{
c.Datetime_Updated,
c.Datetime_Created,
I need something like this (psedocode)
string brancheSearchList = new string "TUP", "LIT" ;
List<string> branchList = new List<string>();
branchList.Add("TUP");
branchList.Add("LIT")
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Created_By == null && c.Company_No == 1 &&
(c.Customer_No == 228 || c.Customer_No == 227) &&
(c.Branch_Id IS IN branchesSearchList)
c# entity-framework linq
2
list.Contains(c.Branch_Id)should generateWHERE column IN (...)
– Fabio
Nov 15 '18 at 10:38
add a comment |
I have already read and tried several links from here but none of them are quite a good fit.
I have a query that currently is searching using a number of or "||" clauses that I need to replace with a dynamicly assigned list. It can be an array or a List<>
My current code:
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Created_By == null && c.Company_No == 1 &&
(c.Customer_No == 228 || c.Customer_No == 227) &&
(c.Branch_Id == "MEM" || c.Branch_Id == "TXK" || c.Branch_Id == "TUP" || c.Branch_Id == "LIT")
&&
c.Shipment_Type == "D" &&
(c.Datetime_Created > dateToSearch || c.Datetime_Updated > dateToSearch) &&
rh.Company_No == 1 &&
rh.Route_Date >= routeDateToSearch
orderby c.Unique_Id_No descending
select new
{
c.Datetime_Updated,
c.Datetime_Created,
I need something like this (psedocode)
string brancheSearchList = new string "TUP", "LIT" ;
List<string> branchList = new List<string>();
branchList.Add("TUP");
branchList.Add("LIT")
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Created_By == null && c.Company_No == 1 &&
(c.Customer_No == 228 || c.Customer_No == 227) &&
(c.Branch_Id IS IN branchesSearchList)
c# entity-framework linq
I have already read and tried several links from here but none of them are quite a good fit.
I have a query that currently is searching using a number of or "||" clauses that I need to replace with a dynamicly assigned list. It can be an array or a List<>
My current code:
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Created_By == null && c.Company_No == 1 &&
(c.Customer_No == 228 || c.Customer_No == 227) &&
(c.Branch_Id == "MEM" || c.Branch_Id == "TXK" || c.Branch_Id == "TUP" || c.Branch_Id == "LIT")
&&
c.Shipment_Type == "D" &&
(c.Datetime_Created > dateToSearch || c.Datetime_Updated > dateToSearch) &&
rh.Company_No == 1 &&
rh.Route_Date >= routeDateToSearch
orderby c.Unique_Id_No descending
select new
{
c.Datetime_Updated,
c.Datetime_Created,
I need something like this (psedocode)
string brancheSearchList = new string "TUP", "LIT" ;
List<string> branchList = new List<string>();
branchList.Add("TUP");
branchList.Add("LIT")
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Created_By == null && c.Company_No == 1 &&
(c.Customer_No == 228 || c.Customer_No == 227) &&
(c.Branch_Id IS IN branchesSearchList)
c# entity-framework linq
c# entity-framework linq
asked Nov 15 '18 at 10:31
Joe RuderJoe Ruder
8871930
8871930
2
list.Contains(c.Branch_Id)should generateWHERE column IN (...)
– Fabio
Nov 15 '18 at 10:38
add a comment |
2
list.Contains(c.Branch_Id)should generateWHERE column IN (...)
– Fabio
Nov 15 '18 at 10:38
2
2
list.Contains(c.Branch_Id) should generate WHERE column IN (...)– Fabio
Nov 15 '18 at 10:38
list.Contains(c.Branch_Id) should generate WHERE column IN (...)– Fabio
Nov 15 '18 at 10:38
add a comment |
1 Answer
1
active
oldest
votes
list.Contains should generate WHERE <column> IN (<comma separated values>)
var branches = new "TUP", "LIT" ;
var result =
cDb.DistributionStopInformations
.Join(cDb.DistributionRouteHeaders, info => info.Route_Code, h => h.Route_Code)
.Where(info => info.Created_By == null)
.Where(info => info.Shipment_Type == "D")
.Where(info => branches.Contains(info.Branch_Id)) // WHERE Branch_Id IN (...)
.ToList();
testing now....but that looks promising.
– Joe Ruder
Nov 15 '18 at 10:49
Thank you Fabio. All it needed was your comment nudge in the right direction: brancheSearchList.Contains(c.Branch_Id) &&
– Joe Ruder
Nov 15 '18 at 11:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317406%2fusing-linq-to-ef-to-search-using-a-array-as-search-parameter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
list.Contains should generate WHERE <column> IN (<comma separated values>)
var branches = new "TUP", "LIT" ;
var result =
cDb.DistributionStopInformations
.Join(cDb.DistributionRouteHeaders, info => info.Route_Code, h => h.Route_Code)
.Where(info => info.Created_By == null)
.Where(info => info.Shipment_Type == "D")
.Where(info => branches.Contains(info.Branch_Id)) // WHERE Branch_Id IN (...)
.ToList();
testing now....but that looks promising.
– Joe Ruder
Nov 15 '18 at 10:49
Thank you Fabio. All it needed was your comment nudge in the right direction: brancheSearchList.Contains(c.Branch_Id) &&
– Joe Ruder
Nov 15 '18 at 11:14
add a comment |
list.Contains should generate WHERE <column> IN (<comma separated values>)
var branches = new "TUP", "LIT" ;
var result =
cDb.DistributionStopInformations
.Join(cDb.DistributionRouteHeaders, info => info.Route_Code, h => h.Route_Code)
.Where(info => info.Created_By == null)
.Where(info => info.Shipment_Type == "D")
.Where(info => branches.Contains(info.Branch_Id)) // WHERE Branch_Id IN (...)
.ToList();
testing now....but that looks promising.
– Joe Ruder
Nov 15 '18 at 10:49
Thank you Fabio. All it needed was your comment nudge in the right direction: brancheSearchList.Contains(c.Branch_Id) &&
– Joe Ruder
Nov 15 '18 at 11:14
add a comment |
list.Contains should generate WHERE <column> IN (<comma separated values>)
var branches = new "TUP", "LIT" ;
var result =
cDb.DistributionStopInformations
.Join(cDb.DistributionRouteHeaders, info => info.Route_Code, h => h.Route_Code)
.Where(info => info.Created_By == null)
.Where(info => info.Shipment_Type == "D")
.Where(info => branches.Contains(info.Branch_Id)) // WHERE Branch_Id IN (...)
.ToList();
list.Contains should generate WHERE <column> IN (<comma separated values>)
var branches = new "TUP", "LIT" ;
var result =
cDb.DistributionStopInformations
.Join(cDb.DistributionRouteHeaders, info => info.Route_Code, h => h.Route_Code)
.Where(info => info.Created_By == null)
.Where(info => info.Shipment_Type == "D")
.Where(info => branches.Contains(info.Branch_Id)) // WHERE Branch_Id IN (...)
.ToList();
answered Nov 15 '18 at 10:44
FabioFabio
20k22048
20k22048
testing now....but that looks promising.
– Joe Ruder
Nov 15 '18 at 10:49
Thank you Fabio. All it needed was your comment nudge in the right direction: brancheSearchList.Contains(c.Branch_Id) &&
– Joe Ruder
Nov 15 '18 at 11:14
add a comment |
testing now....but that looks promising.
– Joe Ruder
Nov 15 '18 at 10:49
Thank you Fabio. All it needed was your comment nudge in the right direction: brancheSearchList.Contains(c.Branch_Id) &&
– Joe Ruder
Nov 15 '18 at 11:14
testing now....but that looks promising.
– Joe Ruder
Nov 15 '18 at 10:49
testing now....but that looks promising.
– Joe Ruder
Nov 15 '18 at 10:49
Thank you Fabio. All it needed was your comment nudge in the right direction: brancheSearchList.Contains(c.Branch_Id) &&
– Joe Ruder
Nov 15 '18 at 11:14
Thank you Fabio. All it needed was your comment nudge in the right direction: brancheSearchList.Contains(c.Branch_Id) &&
– Joe Ruder
Nov 15 '18 at 11:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317406%2fusing-linq-to-ef-to-search-using-a-array-as-search-parameter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
list.Contains(c.Branch_Id)should generateWHERE column IN (...)– Fabio
Nov 15 '18 at 10:38