Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework core 实体框架7(核心)基于复合键查找实体?_Entity Framework Core - Fatal编程技术网

Entity framework core 实体框架7(核心)基于复合键查找实体?

Entity framework core 实体框架7(核心)基于复合键查找实体?,entity-framework-core,Entity Framework Core,是否有基于复合键查找实体的方法或解决方法?使用实体框架7(核心)时 modelBuilder.Entity() .HasKey(c=>new{c.State,c.LicensePlate}); 特别是为了避免多对多中间表的唯一约束异常。通常我使用实体数据库集的上下文。然后我可以做一些类似的事情: _context.Cars.Where(c => c.State != null && c.LicensePlate != null).ToList(); 或者检查任何值是

是否有基于复合键查找实体的方法或解决方法?使用实体框架7(核心)时

modelBuilder.Entity()
.HasKey(c=>new{c.State,c.LicensePlate});

特别是为了避免多对多中间表的唯一约束异常。

通常我使用实体数据库集的上下文。然后我可以做一些类似的事情:

 _context.Cars.Where(c => c.State != null && c.LicensePlate != null).ToList(); 

或者检查任何值是否为“null”0.

通常我使用实体数据库集的上下文。然后我可以做一些类似的事情:

 _context.Cars.Where(c => c.State != null && c.LicensePlate != null).ToList(); 

或者检查任何值是否为“null”0.

您也可以在1.1版本后使用查找方法:

var entity = _context.Cars.Find(firstKey, secondKey);

您还可以在1.1版本后使用Find方法:

var entity = _context.Cars.Find(firstKey, secondKey);

通常,我将上下文与实体的数据库集一起使用。然后我可以做如下操作:_context.Cars.Where(c=>c.State!=null&&c.LicensePlate!=null).ToList();如果这些属性是对象。或者您检查任何值是否为“null”0这对你有帮助吗?啊,是的,简单的方法,而且很有效。我主要需要检查数据库中是否已经存在具有某个复合键的实体。我使用了这种类型的调用:
database.Cars.Any(c=>c.StateId==StateId&&c.LicensePlateId==LicensePlateId)
我是否将其作为答案,这样就可以关闭?或者你们还需要一些帮助吗?对我来说很有用,所以我想这是一个可行的答案。通常我使用实体数据库集的上下文。然后我可以做如下操作:_context.Cars.Where(c=>c.State!=null&&c.LicensePlate!=null).ToList();如果这些属性是对象。或者您检查任何值是否为“null”0这对你有帮助吗?啊,是的,简单的方法,而且很有效。我主要需要检查数据库中是否已经存在具有某个复合键的实体。我使用了这种类型的调用:
database.Cars.Any(c=>c.StateId==StateId&&c.LicensePlateId==LicensePlateId)
我是否将其作为答案,这样就可以关闭?还是你还需要一些帮助?为我工作,我想这是可行的答案。