Using Linq to EF to search using a array as search parameter










0















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)









share|improve this question

















  • 2





    list.Contains(c.Branch_Id) should generate WHERE column IN (...)

    – Fabio
    Nov 15 '18 at 10:38
















0















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)









share|improve this question

















  • 2





    list.Contains(c.Branch_Id) should generate WHERE column IN (...)

    – Fabio
    Nov 15 '18 at 10:38














0












0








0








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)









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 10:31









Joe RuderJoe Ruder

8871930




8871930







  • 2





    list.Contains(c.Branch_Id) should generate WHERE column IN (...)

    – Fabio
    Nov 15 '18 at 10:38













  • 2





    list.Contains(c.Branch_Id) should generate WHERE 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













1 Answer
1






active

oldest

votes


















0














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();





share|improve this answer























  • 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










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
);



);













draft saved

draft discarded


















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









0














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();





share|improve this answer























  • 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















0














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();





share|improve this answer























  • 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













0












0








0







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();





share|improve this answer













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();






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands