'Error retrieving values from ObjectStateEntry

I try to create Database according this tutorial.

This is my Class:

public abstract class File
{
    [Key]
    public string fileName { get; set; }
    public double size{ get; set; }
}

public class SubFile: File
{
    public string secondName{ get; set; }
}

public class MyContext : DbContext
{
    public DbSet<SubFile> subFile{ get; set; }
}

Main

var sb = new SubFile{ fileName = "test.doc" };
sb.secondName= "test2.doc";

using (var db = new MyContext())
{
    db.SubFile.Add(sb);
    db.SaveChanges();
}

After try to save got an error:

Error retrieving values from ObjectStateEntry. See inner exception for details.



Solution 1:[1]

My inner exception was The attempted operation is not supported for the type of object referenced

The error would occur when calling SaveChanges on my database context after adding a new entity to the database.

To solve my problem I had to change my entity so that a complex type IPAddress was instead a string.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Angrist