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

  • Home
  • SEARCH
  • 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 7594993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:33:34+00:00 2026-05-30T21:33:34+00:00

Okay I am trying to make a partial view and controller whose job it

  • 0

Okay I am trying to make a partial view and controller whose job it is to select and display a list of accessories for whatever product is currently being viewed in the parent view.

The database I am working again stores this information in a field that is formatted as a comma separated list, like this:

productnr,productnr2,productnr3,productnr4

So I use the following code to retrieve this list and use it to run the equivalent of an SQL WHERE IN statement:

[ChildActionOnly]
public ActionResult _ListAccessories(string Artnr)
{
    var List = (
        from ArtTbl in db.ArtTbl
        where ArtTbl.ArticleNr == Artnr
        select ArtTbl.AccessoryList)
        .SingleOrDefault();

    var AccList = customFunctions.Accessories(text);

    var AccQuery = 
        from Art in db.ArtTbl
        where AccList.Contains(ArtTbl.ArticleNr)
        select new AccessoryList
        {
            Artnr = ArtTbl.ArticleNr,
            Name = ArtTbl.Namefield_1,
        };

    return PartialView(AccQuery);
}

The function in the AccList variable transforms the first string into the result below. I did this because all the examples I saw used such a syntax, the function seems to work properly as I’ve tested by sending it as a viewBag to the view just to check that it looks correct:

"productnr", "productnr2", "productnr3", "productnr4"

This is what the AccessoryList model looks like as well, just a very simple model:

public class AccessoryList 
{
    public string Artnr { get; set; }
    public string Name { get; set; }

    public AccessoryList()
    {
    }
}

Now this code works, but the problem is that it is too generous, if I have a product number in the list that says “AP500W” then it will also return “AP500” or just “500”. This is a problem as it should only return the exact match.

  • 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-30T21:33:36+00:00Added an answer on May 30, 2026 at 9:33 pm

    The reason you’re having problems begins and ends with this:

    The database I am working again stores this information in a field
    that is formatted as a comma separated list

    LINQ is translating this to a SQL statement that is treating the entire field value as a single entity – because it is a single entity. When Contains() is evaluated, it’s simply looking for matching substring values. That’s why AP500 and 500 match AP500W.

    Since you’re really trying to do the equivalent of WHERE IN (...) you’ll need to convert your MVA (multi-valued attribute) into a set of distinct values.

    The query works in your example where you send a view bag of individual string values:

    "productnr", "productnr2", "productnr3", "productnr4"
    

    Your database value is actually a single string value:

    "productnr, productnr2, productnr3, productnr4"
    

    The difference is subtle but very important. Notice in the second example there is only one string of data that acts as a single value.

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

Sidebar

Related Questions

Okay so I'm trying to make a little gag program that will run away
Okay i'm trying to make ChucK available in exported Processing sketches, i.e. if i
Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay I am trying to make minecraft mods using eclipse. I used this video
Okay so I'm trying to make a file browser program, and I'm in the
Okay, so I'm trying to make a simple content loader which will evolve into
Okay, so I'm trying to make a full text search in multiple columns, something
Okay, so in a program I'm working on in VB.NET I'm trying to make
Okay, I'm trying to make a div fit to the size of the browser
Okay, so I'm trying to make a method that will return the level order

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.