I use Fluent API. I don't like annotations.
I like to always use an autoincrement as my primary key, in all of my tables.
Some of my tables require that two columns, X and Y (where X is not the autoincrement key and Y is not the autoincrement key) have to be unique, ie: there can't be another row such that it has X1=X2 and Y1=Y2. If I wasn't using an autoincrement key, I would simply make these two the key, like this:
modelBuilder.Entity<Foo>() .HasKey(t => new { t.X, t.Y }) .ToTable("Foos");
But, as I said in (2), I'm using autoincrement primary keys
modelBuilder.Entity<Foo>() .HasKey(t => t.someLongId) .ToTable("Foos");
How can I achieve this composite uniqueness in Fluent API?
This is what I want to achieve, written in SQL:
CREATE TABLE `Foos` (
`ID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT ,
...
PRIMARY KEY (`ID`),
UNIQUE KEY (`X`, `Y`)
);