Working on a WPF project using entity Framework 6.
My custom class includes 2 fields that would need to be unique (on top of id). One is a string type, the other one is a custom type.
The implementation of the entity class is s follows:
public partial class MyEntity
{
[Key]
public int Id { get; set; }
[MaxLength(100)]
[Index(IsUnique = true)]
public string Name{ get; set; }
[MaxLength(100)]
[Index(IsUnique = true)]
public MyClass myClass { get; set; }
...
}
Then, when I tray to add a new MyEntity via:
context.SaveChanges();
I get this exception:
Message=Unable to create a constant value of type 'NS.MyClass '. Only primitive types or enumeration types are supported in this context.
Source=EntityFramework
NB: the other unique field (Name) does not generate the exception if I comment the attribute of the MyClass declaration.
Is there really no way to set a custom class as Unique into an entity??
Thx in advance.