0

I'm still working on my Entity Framework fluency... I have a class which contains 3 nullable ints and I want to ensure that explicitly 1 of these 3 properties have a value at any given time. How do I achieve this ?

[key]
public int primary {get; set;}
public int? Id1 { get; set; } <-- this
public int? Id2 { get; set; } <-- this
public int? Id3 { get; set; } <-- this

I think I need to create a clustered index? (I'm honestly unsure)

Also, I am using a MySql database, in-case that is relevant.

Zze
  • 18,229
  • 13
  • 85
  • 118
  • Did you look at [Entity Framework Validation](https://msdn.microsoft.com/en-us/library/gg193959(v=vs.113).aspx) ? – Milster Mar 06 '18 at 11:39
  • @Milster I have not seen that particular link, however the data is not generated from a form. – Zze Mar 06 '18 at 11:42
  • Can't see why that would matter. Especially the interface `IValidatableObject` will provide a method which you can either use on your own and/or EF is using it when you call SaveChanges. – Milster Mar 06 '18 at 11:44
  • @Milster Actually I think you're right! I am going to try and implement that now. I didn't see the part about EF triggering it during `SaveChanges`! – Zze Mar 06 '18 at 11:47

0 Answers0