c# - How to set a custom class as Unique into an Entity in Entity Framework -


working on wpf project using entity framework 6.

my custom class includes 2 fields need unique (on top of id). 1 string type, other 1 custom type.

the implementation of entity class 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 tray add new myentity via:

context.savechanges(); 

i exception:

  message=unable create constant value of type 'ns.myclass '. primitive types or enumeration types supported in context.   source=entityframework 

nb: other unique field (name) not generate exception if comment attribute of myclass declaration.

is there no way set custom class unique entity??

thx in advance.

in entity framework 6 have self. check soultion here: unique key constraints multiple columns in entity framework


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -