我会在前面说我在动态数据上使用linq做了一些非常可怕的事情.但我无法弄清楚为什么这个查询无法编译:
错误1属性"<> h__TransparentIdentifier0"不能与类型参数一起使用
public class Program
{
public static void Main(string[] args)
{
var docs = new dynamic[0];
var q = from doc in docs
where doc["@metadata"]["Raven-Entity-Name"] == "Cases"
where doc.AssociatedEntities != null
from entity in doc.AssociatedEntities
where entity.Tags != null // COMPILER ERROR HERE
from tag in entity.Tags
where tag.ReferencedAggregate != null
select new {tag.ReferencedAggregate.Id, doc.__document_id};
}
}
public static class LinqOnDynamic
{
private static IEnumerable<dynamic> Select(this object self)
{
if (self == null)
yield break;
if (self is … 我将FluentData用作数据库的orm,并尝试创建通用查询方法:
internal static T QueryObject<T>(string sql, object[] param, Func<dynamic, T> mapper)
{
return MyDb.Sql(sql, param).QueryNoAutoMap<T>(mapper).FirstOrDefault();
}
Run Code Online (Sandbox Code Playgroud)
除了我班上的职能:
public class MyDbObject
{
public int Id { get; set; }
}
public static MyDbObject mapper(dynamic row)
{
return new MyDbObject {
Id = row.Id
};
}
public static MyDbObject GetDbObjectFromTable(int id)
{
string sql = @"SELECT Id FROM MyTable WHERE Id=@Id";
dynamic param = new {Id = id};
return Query<MyDbObject>(sql, param, mapper);
}
Run Code Online (Sandbox Code Playgroud)
在Query<MyDbObject>(sql, param, mapper)编译器上说:
An anonymous function or …