Entity Framework7(核心)根据组合键查找实体?
Entity Framework 7 (core) Find entity based on composite key?
是否有基于组合键查找实体的方法或解决方法?当使用 Entity Framework 7 (core).
modelBuilder.Entity<Car>()
.HasKey(c => new { c.State, c.LicensePlate });
特别是为了避免多对多中间的 UNIQUE 约束异常 table。
通常我使用带有实体 DBSets 的上下文。然后我可以做类似的事情:
_context.Cars.Where(c => c.State != null && c.LicensePlate != null).ToList();
或者您检查 "null" 的任何值。 != 0.
在 1.1 发布后您也可以使用 Find 方法:
var entity = _context.Cars.Find(firstKey, secondKey);
是否有基于组合键查找实体的方法或解决方法?当使用 Entity Framework 7 (core).
modelBuilder.Entity<Car>()
.HasKey(c => new { c.State, c.LicensePlate });
特别是为了避免多对多中间的 UNIQUE 约束异常 table。
通常我使用带有实体 DBSets 的上下文。然后我可以做类似的事情:
_context.Cars.Where(c => c.State != null && c.LicensePlate != null).ToList();
或者您检查 "null" 的任何值。 != 0.
在 1.1 发布后您也可以使用 Find 方法:
var entity = _context.Cars.Find(firstKey, secondKey);