没有通用方法';其中';关于类型';System.Linq.Queryable';与提供的类型参数和参数兼容
我想使用IQueryable检索特定记录。但我得到错误“No generic method”,其中“on type”System.Linq.Queryable与提供的类型参数和参数兼容。如果方法是非泛型的,则不应提供类型参数。“。我获得了选定的行id,但无法显示它。这是我的密码没有通用方法';其中';关于类型';System.Linq.Queryable';与提供的类型参数和参数兼容,linq,iqueryable,Linq,Iqueryable,我想使用IQueryable检索特定记录。但我得到错误“No generic method”,其中“on type”System.Linq.Queryable与提供的类型参数和参数兼容。如果方法是非泛型的,则不应提供类型参数。“。我获得了选定的行id,但无法显示它。这是我的密码 internal static IQueryable GetRecordsFromPrimaryKeys(this IQueryable datasource, List<FilterDescriptor>
internal static IQueryable GetRecordsFromPrimaryKeys(this IQueryable datasource, List<FilterDescriptor> primaryKeys)
{
IQueryable data = datasource;
ParameterExpression paramExp = null;
bool firstLoop = false;
System.Linq.Expressions.Expression predicate = null;
var RecordType = datasource.GetObjectType();
paramExp = RecordType.Parameter();
foreach (FilterDescriptor primaryKey in primaryKeys)
{
if (!(firstLoop))
{
predicate = data.Predicate(paramExp, primaryKey.ColumnName, primaryKey.Value, FilterType.Equals, false, RecordType);
firstLoop = true;
}
else
{
predicate = predicate.AndPredicate(data.Predicate(paramExp, primaryKey.ColumnName, primaryKey.Value, FilterType.Equals, false, RecordType));
}
}
if (paramExp != null && predicate != null)
{
var lambda = Expression.Lambda(predicate, paramExp);
data = data.Provider.CreateQuery(
Expression.Call(
typeof(Queryable),
"Where",
new Type[] { data.ElementType },
data.Expression,
lambda
)
);
}
return data;
}
内部静态IQueryable GetRecordsFromPrimaryKeys(此IQueryable数据源,列出primaryKeys)
{
IQueryable数据=数据源;
ParameterExpression ParameterXP=null;
bool firstLoop=false;
System.Linq.Expressions.Expression谓词=null;
var RecordType=datasource.GetObjectType();
ParameterXP=RecordType.Parameter();
foreach(primaryKeys中的FilterDescriptor primaryKey)
{
如果(!(第一循环))
{
谓词=data.predicate(参数xp,primaryKey.ColumnName,primaryKey.Value,FilterType.Equals,false,RecordType);
firstLoop=true;
}
其他的
{
predicate=predicate.AndPredicate(data.predicate(参数xp,primaryKey.ColumnName,primaryKey.Value,FilterType.Equals,false,RecordType));
}
}
if(paramExp!=null&&predicate!=null)
{
var lambda=Expression.lambda(谓词,参数xp);
data=data.Provider.CreateQuery(
表情,打电话(
类型(可查询),
“哪里”,
新类型[]{data.ElementType},
数据。表达式,
兰姆达
)
);
}
返回数据;
}
我的代码适用于IEnumerable/IQueryable/ICollection。但是当我使用关键字virtual和type作为ICollection指定类时,它抛出异常。我的代码是
public class RoomType
{
public int ID { get; set; }
[MaxLength(10, ErrorMessage = "Room code cannot be longer than 10 characters.")]
public string Code { get; set; }
[MaxLength(50, ErrorMessage = "Room name cannot be longer than 50 characters.")]
public string Name { get; set; }
public virtual ICollection<RoomCategory> RoomCategories { get; set; }
}
公共类RoomType
{
公共int ID{get;set;}
[MaxLength(10,ErrorMessage=“房间代码不能超过10个字符。”)]
公共字符串代码{get;set;}
[MaxLength(50,ErrorMessage=“房间名称不能超过50个字符。”)]
公共字符串名称{get;set;}
公共虚拟ICollection RoomCategories{get;set;}
}
使用关键字“virtual”时,某些随机值会附加到“RecordType”中。我认为这导致了例外。仍在寻找解决方案
我不知道出了什么问题。欢迎任何建议
谢谢。我刚刚遇到了类似的情况。问题源于这样一个事实:在某些情况下,您处理的是“代理”,而不是实际的实体。因此,您需要确保
RecordType
与data.ElementType
匹配
尝试:
或更好的方法,请尝试:
var recordType = data.ElementType
我只是遇到了类似的情况。问题源于这样一个事实:在某些情况下,您处理的是“代理”,而不是实际的实体。因此,您需要确保
RecordType
与data.ElementType
匹配
尝试:
或更好的方法,请尝试:
var recordType = data.ElementType
尝试使用
typeof(可枚举)
而不是typeof(可查询)
尝试使用typeof(可枚举)
而不是typeof(可查询)
我认为你的代码应该可以工作。您确定所有类型都匹配吗?我认为您的代码应该可以工作。你确定你所有的类型都匹配吗?嘿..谢谢deverop。它就像一个符咒:)。谢谢!。嘿..谢谢你,德维洛普。它就像一个符咒:)。谢谢!。