如果表之间存在多对多关系,如何在 Entity Framework 中获得交集?
How to get intersection in Entity Fraemwork if relationship between tables many-to-many?
我有这个型号(型号比较多,现在不重要了)
我有一些注释,我想让所有用户知道如何使用这些注释,但我得到了这个异常(“无法创建 'DataBase.Annotation' 类型的常量值。
在此上下文中仅支持原始类型或枚举类型。"),使用下一个代码时
TextCorporaEntities TextCorporaContext = new TextCorporaEntities();
List<DataBase.Annotation> annotations = //annotations which I used
//I get the exception here
var UserAnnotationsResult = TextCorporaContext.Annotation_User.
Where(x => annotations.
Contains(x.Annotation));
我可以使用这段代码,但效率不高
List<Annotation_User> listResult = new List<Annotation_User>();
foreach (var x in annotations)
{
listResult.Concat(TextCorporaContext.Annotation_User.Where(y=>y.AnnotationId == x.Id));
}
如何获取所有使用了某些注释的用户?
如何获取所有使用某些注释的用户,其中 AccessType 等于 ReadOrWrite(在模型中它保存在字符串中)?
您只能将 Contains 与原语一起使用
我认为这应该可行
var annotationsIds = annotations.Select(a => a.AnnotationId)
var UserAnnotationsResult = TextCorporaContext.Annotation_User.
Where(x => annotationsIds.
Contains(x.Annotation.AnnotationId));
我有这个型号(型号比较多,现在不重要了)
我有一些注释,我想让所有用户知道如何使用这些注释,但我得到了这个异常(“无法创建 'DataBase.Annotation' 类型的常量值。 在此上下文中仅支持原始类型或枚举类型。"),使用下一个代码时
TextCorporaEntities TextCorporaContext = new TextCorporaEntities();
List<DataBase.Annotation> annotations = //annotations which I used
//I get the exception here
var UserAnnotationsResult = TextCorporaContext.Annotation_User.
Where(x => annotations.
Contains(x.Annotation));
我可以使用这段代码,但效率不高
List<Annotation_User> listResult = new List<Annotation_User>();
foreach (var x in annotations)
{
listResult.Concat(TextCorporaContext.Annotation_User.Where(y=>y.AnnotationId == x.Id));
}
如何获取所有使用了某些注释的用户? 如何获取所有使用某些注释的用户,其中 AccessType 等于 ReadOrWrite(在模型中它保存在字符串中)?
您只能将 Contains 与原语一起使用
我认为这应该可行
var annotationsIds = annotations.Select(a => a.AnnotationId)
var UserAnnotationsResult = TextCorporaContext.Annotation_User.
Where(x => annotationsIds.
Contains(x.Annotation.AnnotationId));