logo
down
shadow

Unable to create a constant value of type 'Project.Models.Subcategory'. Only primitive types or enumeration types are su


Unable to create a constant value of type 'Project.Models.Subcategory'. Only primitive types or enumeration types are su

Content Index :

Unable to create a constant value of type 'Project.Models.Subcategory'. Only primitive types or enumeration types are su
Tag : chash , By : ChristianM
Date : November 24 2020, 01:01 AM

I wish did fix the issue.
The point is that the value of businesses should be null. But when I checked in the debugger it has a value like this: {System.Data.Entity.Infrastructure.DbQuery}.
var businesses = db.Businesses.Where(b => b.StateID == rvm.StateID
             && b.Subcategories.Any(s => s.SubcategoryName == sub.SubcategoryName));
int businesses = db.Businesses.Count(b => b.StateID == rvm.StateID
                        && b.Subcategories.Any(s => s.SubcategoryName == sid));
if (businesses <= 0)
    return View("NoBusinessFoundInSubcategory");

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

LINQ, Unable to create a constant value of type XXX. Only primitive types or enumeration types are supported in this con


Tag : chash , By : user93312
Date : March 29 2020, 07:55 AM
Any of those help In my application I have Lecturers and they have list of Courses they can teach and when I'm deleting a course I want to remove connection to lecturers. Here's the code: , You can't use Contains with non-primitive values. Do
Where(l => l.Courses.Select(c => c.CourseId).Contains(courseId)

Unable to create a constant value of type ''YYY". Only primitive types or enumeration types are supported in this c


Tag : linq , By : Gabe
Date : March 29 2020, 07:55 AM
I hope this helps you . I have an entity Person and a view model that contains a collection of persons. , You can do like this ,
var Ids=vm.PersonCollection.Select(y => y.Id).ToArray();

ICollection<Person> prsn =
 new PersonRepository().GetAll().Where(x => Ids.Contains(x.Id)).ToList();

Unable to create a constant value of type 'X.Models.Game'. Only primitive types or enumeration types are supported in th


Tag : asp.net , By : ap.
Date : March 29 2020, 07:55 AM
To fix the issue you can do Not sure if it will work, but try instru.Games.Any(q => q.Id == selectedGame.Id) instead of instru.Games.Contains(selectedGame).
Hope this helps!

Asp.Net - Unable to create a constant value of type. Only primitive types or enumeration types are supported in this con


Tag : chash , By : Jesenko Mehmedbasic
Date : March 29 2020, 07:55 AM
this will help I suspect that the problem is that you are using a complex type in your query for comparison f.UpFile.Equals(upFile)
Why don't you try comparing by a primitive type such as the upFile id for example?
 var fields = from f in db2.Fields
                      where f.UpFile.ID == upFile.ID
                      select f;
 ViewBag.Fields = fields.ToList();

Unable to create a constant value of type 'AddressModel'. Only primitive types or enumeration types are supported in thi


Tag : chash , By : Anna
Date : March 29 2020, 07:55 AM
I wish this help you That is because childContactAddress object (and also taxReceiptChargesModelList) is already in memory and when you try to assign a complex object in the projection of your second query, the Linq provider can't translated that object to SQL. One option can be call AsEnumerable extension method:
  return unitOfWork.LegacyTaxReceiptStore.GetQuery()
        .Where(ltr => ltr.LegacyTaxReceiptId ==ltrm.LegacyTaxReceiptId)
        .AsEnumerable()
        .Select(c => new TaxReceiptsWithChargesModel()
        {
            LegacyTaxReceiptId = ltrm.LegacyTaxReceiptId,
            ChildContactId = ltrm.ChildContactId,
            ChildContact = ltrm.ChildContact,
            EmailAddress = ltrm.EmailAddress,
            ChildId = ltrm.ChildId,
            ChildName = ltrm.ChildName,
            ChargesTotal = ltrm.ChargesTotal,
            TaxReceiptAmount = ltrm.TaxReceiptAmount.Value,
            TaxReceiptYear = ltrm.TaxReceiptYear,
            Address = childContactAddress,
            ReceiptNumber = $"{ltrm.TaxReceiptYear}-{ltrm.LegacyTaxReceiptId.ToString().PadLeft(6, '0')}",
            Charges = taxReceiptChargesModelList, 
        }).FirstOrDefault();
var result=unitOfWork.LegacyTaxReceiptStore.GetQuery()
            .FirstOrDefault(ltr => ltr.LegacyTaxReceiptId ==ltrm.LegacyTaxReceiptId);

return new TaxReceiptsWithChargesModel()
        {
            LegacyTaxReceiptId = result.LegacyTaxReceiptId,
            ChildContactId = result.ChildContactId,
            ChildContact = result.ChildContact,
            EmailAddress = result.EmailAddress,
            ChildId = result.ChildId,
            ChildName = result.ChildName,
            ChargesTotal = result.ChargesTotal,
            TaxReceiptAmount = result.TaxReceiptAmount.Value,
            TaxReceiptYear = result.TaxReceiptYear,
            Address = childContactAddress,
            ReceiptNumber = $"{result.TaxReceiptYear}-{result.LegacyTaxReceiptId.ToString().PadLeft(6, '0')}",
            Charges = taxReceiptChargesModelList,
        };
Related Posts Related QUESTIONS :
  • How do I make event callbacks into my win forms thread safe?
  • Genealogy Tree Control
  • WCF Service - Backward compatibility issue
  • Binary patch-generation in C#
  • Tab Escape Character?
  • When do Request.Params and Request.Form differ?
  • The imported project "C:\Microsoft.CSharp.targets" was not found
  • Numeric Data Entry in WPF
  • Print a Winform/visual element
  • C# logic order and compiler behavior
  • When to use an extension method with lambda over LINQtoObjects to filter a collection?
  • How to make a button appear as if it is pressed?
  • C# and Arrow Keys
  • How do you resolve a domain name to an IP address with .NET/C#?
  • Should the folders in a solution match the namespace?
  • How can I evaluate C# code dynamically?
  • CSharpCodeProvider Compilation Performance
  • How can I create Prototype Methods (like JavaScript) in C#.Net?
  • DataTable Loop Performance Comparison
  • CSV string handling
  • What is the best way to do unit testing for ASP.NET 2.0 web pages?
  • High availability
  • What to use for Messaging with C#
  • Accessing a Dictionary.Keys Key through a numeric index
  • ConfigurationManager.AppSettings Performance Concerns
  • What Are Some Good .NET Profilers?
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com