1

One of the requirements of a module I am currently building requires me to select data using Linq but the ids are being passed to me thru an integer array

        var CheckedArray = Request["doc_download"];
        string[] detailIds = CheckedArray.Split(',');
        List<int> dtIds = new List<int>();
        foreach (string words in detailIds)
        {
            dtIds.Add(Int32.Parse(words));
        }


      using (var ctx = new Connect2020Entities())
        {
           DetailList = (from userDetail in ctx.DocumentDetail
           where userDetail.ID == <!-- items in dtIds --> //<<I do not know what could be used to compare all of the data from the array in a single query>>

           select new DetailList()
           {
             FilePath = userDetail.FilePath
           }).ToList<UserDocument>();
        }

What could be done so that all of the ids inside the integer array can be compared inside the query in one go. I currently could not think of a viable logic that will allow the values in the array to be used as parameters in the query I am using.

*The DocumentDetail field ID is an integer.

1 Answer 1

1

you can try is use Contains()

ctx.DocumentDetail.Where(ele => dtIds.Contains(ele.ID)).ToList();

or in your current syntax

where dtIds.Contains(userDetail.ID)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.