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

The Archive Base Latest Questions

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

Can somebody help me resolve this exception: Test method KravmagaTests.Model.Entities.StudentTest.Create_Valid_Student threw exception: System.NotSupportedException: Unable

  • 0

Can somebody help me resolve this exception:

Test method
KravmagaTests.Model.Entities.StudentTest.Create_Valid_Student threw
exception: System.NotSupportedException: Unable to create a constant
value of type ‘Kravmaga.Models.Account’. Only primitive types (‘such
as Int32, String, and Guid’) are supported in this context.

I get this when I run this test method:

[TestMethod]
public void Create_Valid_Student()
{
    Student student = new Student()
    {
        Username = "username",
        Firstname = "firstname",
        Surname = "surname",
        Email = "email@gmail.com",
        Password = "password",
    };
    KravmagaContext context = new KravmagaContext();
    context.AddToAccounts(student);
    context.Save();
    bool exists = context.Accounts.Contains(student); // THIS THROWS EXCEPTION
    Assert.IsTrue(exists);
}

Thanks a lot.

  • 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-25T20:53:23+00:00Added an answer on May 25, 2026 at 8:53 pm

    Change your test method this way:

    // ...
    context.Save();
    int newStudentId = student.Id;
    // because the Id generated by the DB is available after SaveChanges
    
    bool exists = context.Accounts.Any(a => a.Id == newStudentId);
    Assert.IsTrue(exists);
    

    Contains doesn’t work here because it checks if a particular object instance is in the context.Accounts set. Translation of this check into SQL is not supported, only for primitive types (like the exception says). Any just translates the filter expression you specify into SQL and passes it to the database.

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

Sidebar

Related Questions

Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
can somebody help me select the url from this XML document where the ID
Can somebody help me convert this VB function to Perl (PHP, Ruby or Python
Can somebody help me understand how this pointed corner was actually generated in css
Can somebody help me with this: When I try to run the project, this
Hi people I been trying to do this the whole night, can somebody help
Can somebody help me construct this regular expression, please... Given the following strings... "April
Can somebody help on this one. I am trying to set the name of
Can somebody help me with this problem, I dont know why there is an
I am new to Java. Can somebody help me? Is there any method available

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.