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.
Change your test method this way:
Containsdoesn’t work here because it checks if a particular object instance is in thecontext.Accountsset. Translation of this check into SQL is not supported, only for primitive types (like the exception says).Anyjust translates the filter expression you specify into SQL and passes it to the database.