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 8287959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:10:40+00:00 2026-06-08T12:10:40+00:00

I have a work around for this issue, however I would appreciate it if

  • 0

I have a work around for this issue, however I would appreciate it if someone could explain why this is happening and how I would design this for large datasets where my work around would not be viable.

The full error is:
Unable to create a constant value of type ‘THPT_Razor.Models.WinType’. Only primitive types (‘such as Int32, String, and Guid’) are supported in this context.

and I am using EF v4.0.

The commented lines are the offending code and the work around is the “For loop”

Thank you in advance.

List<WinType> _atype = db.WinTypes.Where(wt => wt.IsWin == false).ToList();
List<WinType> _wtype = db.WinTypes.Where(wt => wt.IsWin == true).ToList();
string test = _wtype.Where(wt => wt.Value ==0).Select(wt => wt.Description).SingleOrDefault();
List<WinCheckDetails> wcd = db.Wins.Include("UserProfiles").Where(w => w.venueLogId == logid).Select(w => new WinCheckDetails
{
    //awarddesc = w.atypeid.HasValue ? _atype.Where( wt=> wt.Value == w.atypeid).Select(wt => wt.Description).SingleOrDefault():string.Empty,
    //windesc = _wtype.Where(wt => wt.Value == w.typeid).Select(wt => wt.Description).Single(),
    atypeid = w.atypeid,
    typeid = w.typeid,
    WinId = w.WinId,
    other = w.other,
    posterid = w.posterid,
    confirmed = w.confirmed,
    posttime = w.posttime,
    game = w.game,
    playerid = w.UserProfile.PlayerID,
    firstname = w.UserProfile.FirstName,
    lastname = w.UserProfile.LastName,
    fullname = w.UserProfile.FirstName + " " + w.UserProfile.LastName
}).OrderBy(o => o.game).ToList();
foreach (WinCheckDetails wc in wcd)
{
    wc.awarddesc = _atype.Where(wt => wt.Value == wc.atypeid).Select(wt => wt.Description).SingleOrDefault();
    wc.windesc = _wtype.Where(wt => wt.Value == wc.typeid).Select(wt => wt.Description).SingleOrDefault();
}
  • 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-06-08T12:10:42+00:00Added an answer on June 8, 2026 at 12:10 pm

    _atype and _wtype are lists of WinType in memory because you are applying ToList() to the queries. With respect to database queries they are collections of constant values because to perform the query in the database they have to be transmitted to the database server as the values they are in memory. EF doesn’t support to transfer such constant values or collections of values from memory to the database unless they are values of primitive types (int for example). That’s the reason why you get an exception.

    Did you try to use _atype and _wtype as IQueryable instead of lists:

    IQueryable<WinType> _atype = db.WinTypes.Where(wt => !wt.IsWin);
    IQueryable<WinType> _wtype = db.WinTypes.Where(wt => wt.IsWin);
    
    List<WinCheckDetails> wcd = db.Wins
        .Where(w => w.venueLogId == logid)
        .Select(w => new WinCheckDetails
        {
            awarddesc = w.atypeid.HasValue
                ? _atype.Where(wt=> wt.Value == w.atypeid)
                        .Select(wt => wt.Description).FirstOrDefault()
                : string.Empty,
            windesc = _wtype.Where(wt => wt.Value == w.typeid)
                            .Select(wt => wt.Description).FirstOrDefault(),
    
            // ... (unchanged)
        }).OrderBy(o => o.game).ToList();
    

    I have removed the Include because it will be ignored anyway when you perform a projection with Select. Also I have replaced SingleOrDefault and Single by FirstOrDefault because both are not supported in a projection (and First neither), only FirstOrDefault is supported.

    I am not sure if that will work. But it should remove your exception (but maybe you’ll get another one…).

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

Sidebar

Related Questions

I have a work around for this problem, but I've been noticing some peculiar
I have been dancing around this issue for awhile but it keeps coming up.
What options do I have to work around disabled cookies for session management?
Since batch doesn't really have ints, I have to work around it with set
PLEASE NOTE, I have found a work around which actually works out better for
I have some experience in ASP.Net and can work my way around it without
I have finally started messing around with creating some apps that work with RESTful
I have been reading around this subject all morning, but I am still confused
The commandlink link2 does not have work after an ajax call is made to
I have a large sql dump file ... with multiple CREATE TABLE and INSERT

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.