我在这里使用包含来创建 IN 语句:
public static List<Identity> GetIdentity(dbEntities db, string[] types)
{
var query = (
from au in db.user
from c in db.career
.Where(x => x.emp_nb == au.emp_nb).DefaultIfEmpty()
.Where(x => types.Contains(x.type)) // here it is!
select new Identity
{
userlogin = au.User_Login,
first_name = au.User_First_Name,
last_name = au.User_Last_Name,
}
).Distinct();
return query.ToList();
}
当types
数组有一个元素时,这很有用。
如果在调试会话期间有两个或更多元素,我会得到:
在0x00007FFDB3117788(KernelBase.dll)中抛出异常 Migration_Module.exe:0xC0000005:访问冲突读取位置 0x0000000000000018。
并且引发了谴责:
System.NullReferenceException:
en MySql.Data.Entity.SelectStatement.AddDefaultColumns(Scope scope)
en MySql.Data.Entity.SelectStatement.Wrap(Scope scope)
en MySql.Data.Entity.SelectGenerator.Visit(DbApplyExpression expression)
en MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type)
en MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type)
en MySql.Data.Entity.SelectGenerator.Visit(DbProjectExpression expression)
en MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type)
en MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type)
en MySql.Data.Entity.SelectGenerator.Visit(DbDistinctExpression expression)
en MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type)
en MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type)
en MySql.Data.Entity.SelectGenerator.Visit(DbProjectExpression expression)
en MySql.Data.Entity.SelectGenerator.GenerateSQL(DbCommandTree tree)
en MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
en System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
en System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
en System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters, AliasGenerator aliasGenerator)
en System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
en System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
en System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
en System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
en System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
en SF_Migration_Module.queries.Queries.GetIdentity(dbEntities db, String[] types)
我正在使用:
答案 0 :(得分:0)
升级到EntityFramework 6解决了我的问题。
Install-Package EntityFramework
Install-Package MySql.Data.Entity -Version 6.9.9