gpt4 book ai didi

c# - MySQL Entity Framework - 当多个元素作为参数传递时,Contains 方法会引发异常

转载 作者:行者123 更新时间:2023-11-29 19:09:16 26 4
gpt4 key购买 nike

这里我使用Contains来创建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 数组只有一个元素时,这非常有效。

当在调试 session 期间它有两个或更多元素时,我得到:

Exception thrown at 0x00007FFDB3117788 (KernelBase.dll) in Migration_Module.exe: 0xC0000005: Access violation reading location 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)

我正在使用:

  • Visual Studio 2015
  • Entity Framework 5
  • MySQL NET 连接器 6.9.9

最佳答案

升级到 EntityFramework 6 解决了我的问题。

Install-Package EntityFramework
Install-Package MySql.Data.Entity -Version 6.9.9

关于c# - MySQL Entity Framework - 当多个元素作为参数传递时,Contains 方法会引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43227080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com