I have a table that contains an Id column as a primary key. There is also a requirement to enforce uniqueness on two other columns, which are actually FKs. In Sql Server I can create a UniqueKey on this two columns.
What can I do on the EF side so that it can validate uniqueness over these two fields?
EF doesn’t support unique keys so your best workaround is to use unique key in the database and catch exception during saving. If you need EF to create the unique key during database creation you can use custom initializer.
If you want to have some validation in the application you will need to execute some query and check that these data don’t exist yet but you will still need to use the former advice with catching exception because another thread / process / user can create such data between your query and saving changes.