0

I have a model that has two foreign keys (as well as a primary key). I want to set the two fks unique together (meaning there can't be two columns with both having the same two fk values).

I've tried everything but I keep getting: "The type 'Model.MyType' must be a non-nullable value type in order to use it as a parameter 'T'". This error is in the Property function:

Property (o => o.MyType).HasColumnAnnotation (IndexAnnotation.AnnotationName,
new IndexAnnotation (new IndexAttribute ("UX_MyConstraint", 1) {IsUnique = true}));

(And another one with 2).

I prefer a fluent api solution but data annotations are fine too.

(C# entity framework 6.1 code first)

Thanks!

Ella Sharakanski
  • 2,683
  • 3
  • 27
  • 47
  • How is declared MyType? As not nullable? – bubi Jun 22 '15 at 07:17
  • As another class that is a table in the DB. The relation is required so the fk appears as required in the DB but MyType is a reference type so it is nullable – Ella Sharakanski Jun 22 '15 at 08:02
  • Maybe you post a little more of your code, so things get clearer. Also you are trying to create a unique index here, but indices are used to guarantee unique row values. If you want the column values to be unique you have to look into CHECK constraints. – Florian Haider Jun 22 '15 at 08:15

0 Answers0