Reputation: 974
Is there a method or workaround to find entity based on composite key? When using Entity Framework 7 (core).
modelBuilder.Entity<Car>()
.HasKey(c => new { c.State, c.LicensePlate });
Specially to avoid UNIQUE constrain exceptions with many-to-many intermediate table.
Upvotes: 1
Views: 429
Reputation: 291
You can use also Find method after 1.1 release:
var entity = _context.Cars.Find(firstKey, secondKey);
Upvotes: 3
Reputation: 116
Usually I use a Context with DBSets of the entities. Then I can do something like:
_context.Cars.Where(c => c.State != null && c.LicensePlate != null).ToList();
Or you check against whatever value would be "null". != 0.
Upvotes: 1