我写了一个应用程序,我使用它作为代理查询数据库中的数据,并自动加载到我的分布式Web缓存中。
我通过指定一个 SQL 查询和一个配置中的类型来完成这个。实际执行查询的代码如下:
List<Object> result = null;
try { result = dc.ExecuteQuery(elementType, entry.Command).OfType<Object>().ToList(); }
catch (Exception ex) { HandleException(ex, WebCacheAgentLogEvent.DatabaseExecutionError); continue; }
elementType
是从配置中指定的类型创建的System.Type(使用Type.GetType()
),而entry.Command
是SQL查询。
我所遇到问题的特定实体类型看起来像这样:
public class FooCount
{
[Column(Name = "foo_id")]
public Int32 FooId { get; set; }
[Column(Name = "count")]
public Int32 Count { get; set; }
}
SQL查询看起来像这样:
select foo_id as foo_id, sum(count) as [count]
from foo_aggregates
group by foo_id
order by foo_id
由于某些原因,在执行查询时,“Count”属性最终被填充,但“FooId”属性却没有被填充。我尝试自己运行查询,正确的列名被返回,并且列名与我在映射属性中指定的匹配。帮帮我!