Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:54:51+00:00 2026-05-22T20:54:51+00:00

I have a situation where I need to display ItemID and ItemName from Items

  • 0

I have a situation where I need to display ItemID and ItemName from Items table. Let’s say ItemID is 002, and ItemName is Apple. I have another field called SupplementaryItems in the table which stores related ItemID seperated by | (delimiter), something like 003|004|005. I am using MVC3 with a repository pattern, something like

var items = _dataContext.items.AsQueryable();
items = from i in items 
          where i.Item_ID.equals(itemId)
           select i;

The above query with an itemId 002 will return Apple which works fine. Now, I also need to display all the supplementaryItems with their corresponding ItemName which means I need to split the supplementaryItem into array and use something like supplementaryItemArray contains itemID. But in this case, I need two separate calls to database, first one will return only item with itemID where I store the supplementaryItemID in a variable.

 var supplementMaterialsArr = supplementMaterials.ToString().Split('|');

and second one will return all the items, and I will loop through the second one to get the ItemName from the ItemID. FYI, this approach requires two separate calls to be made from controller, something like

var itemInformationAll = _repository.GetAllItems();
var itemInformation = _repository.GetItemDetailInformation(id); 

I think this is not so efficient approach. Anybody has better solution to this? Should I use LINQ self join? But if I use self join, will I able to get the supplemetaryItem with their corresponding ItemName with a single query?
Any suggestions would be highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:54:52+00:00Added an answer on May 22, 2026 at 8:54 pm

    This is the best I could come up with. It will result in two queries, but never pulls the entire table into memory.

    var q = from item in
            (from item in TblItems
            where item.ItemID == 1
            select new
            {
                Name = item.ItemName,
                SupplementaryItems = item.SupplementaryItems.Split('|')
            }).AsEnumerable()
            select new
            {
                Name = item.Name,
                SupplementaryItems = TblItems.Where (x => 
                    item.SupplementaryItems.Select(y => int.Parse(y))
                    .Contains(x.ItemID))
            };
    

    I would however recommend to change the DB structure ta have a seperate table for the referencing items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a situation where we need to display data from a database in
I have a situation where I need to display a double value rounded to
I have the following situation: I need to save data from an Intent's putExtra
I have a situation in which I need to display a string with some
I have a situation where I pull data from a table by date. If
I have this situation where I need to display a bunch of files pulled
I have situation where I need to change the order of the columns/adding new
I have a situation where I need to dynamically build up a list of
I have a situation where I need to pass two parameters to an action.
I have a situation where I need to update a control referenced in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.