- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我编写了一个应用程序,用作从数据库查询数据并自动将其加载到我的分布式网络缓存中的代理。
我通过在配置中指定一个 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”属性不会。我尝试自己运行查询,返回了正确的列名,并且列名与我在映射属性中指定的相匹配。帮助!
最佳答案
这太疯狂了......
解决我问题的方法是用 TableAttribute
装饰我的实体类:
[Table(Name = "foo_aggregates")]
public class FooCount
{
[Column(Name = "foo_id")]
public Int32 FooId { get; set; }
[Column(Name = "count")]
public Int32 Count { get; set; }
}
我曾假设(显然是错误的)因为我没有使用 GetTable<T>()
方法,我不需要相应的映射属性。
更新:一年半之后,我终于明白了,似乎属性上的 ColumnAttribute 装饰被忽略了,除非类上有相应的 TableAttribute 装饰。这解释了为什么要填充“Count”属性,因为它的命名与 SQL 语句中的列匹配,而 FooId/foo_id 当然不匹配。
关于c# - LINQ-to-SQL:ExecuteQuery(Type, String) 填充一个字段,但不填充另一个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/591097/
我有两个类:样本和参数。我还有一个sample_sample_parameter查找表,该表用于保存样本ID和参数ID。这映射在我的grails应用程序中。 我能够编写一个可在松鼠中使用的sql查询:
我有一个由以下人员执行的 SQL 查询: ResultSet resultSet = preparedStatement.executeQuery(); while( resultSet.next()
我有一个问题,我尝试使用 sp 但我得到了 The executeQuery method must return a result 如果我使用 cs.execute(); 和 ResultSet r
我正在创建一个简单的应用程序,它使用 JDBC 从 MySQL 获取数据。我使用 dao 从数据库中获取数据。除了一个之外,所有其他都工作正常(所有 DAO 的代码都相同)。此外,我还手动提交 INS
下面的语句是否存在任何条件 PreparedStatement.executeQuery() 不返回或抛出异常? 最佳答案 这取决于您使用的数据库和配置的隔离级别。一个常见的默认设置是,如果您尝试选择
我在返回结果集中收到此错误。无法将结果集的结果转换为 double 。 不是可以返回一个double吗?我该怎么办? public double getBalance( String name ) {
我正在处理一个包含三个表的数据库: 我想插入一条新记录,首先将信息添加到 DonorInformation 和 NeedyInformation 中。然后,从两条记录中获取主 ID 后,应将其插入到
我正在尝试编写一个方法来检查我的数据库,如果用户有权执行某个方法。 执行查询后得到的响应为空。 我有以下方法可以做到这一点: public boolean checkRole(String e
ExecuteQuery() 方法返回一个 IEnumerable,但有没有办法让它返回 IQueryable? 最佳答案 嗯,你可以调用AsQueryable ,但不会有任何好处。问题是当你使用 E
我使用 Breeze Promise ExecuteQuery 从数据库获取数据: var getdata = function(){ var manager = new breeze.Ent
我有 3 个 jComboBox。第一个是房间类型。当我在第一个 jComboBox 上选择房间类型时,它必须在第二个 jComboBox 中显示所有可用房间,但是当我选择其中一个房间类型时,会弹出错
我的查询 def myQuery = PublicTraining.executeQuery("SELECT t.id, t.isSoldOut, t.course.ebPrice, t.offe
statement = conRecieved.createStatement(); resultSet = statement.executeQuery("Select * from actor")
我正在使用最新的(截至今天)BreezeJS、AngularJS、.NET、Entity Framework 等。 我有一个看起来设置正确的 Breeze 应用程序,但是从 executeQuery(
以下 Java 代码返回一个空结果集,但 SQL 显示表中有数据: @Override public List list() { List list = new ArrayList<>();
这个问题已经有答案了: Invalid state, the ResultSet object is closed (1 个回答) 已关闭 8 年前。 给出以下代码: //connection
我正在使用 ExecuteQuery (www.executequery.org ) 连接到远程 Oracle 数据库。我收到了一个 .sql 文件,我应该在这个数据库上运行它。但我什至无法将此文件加
似乎无法解决这个问题。在过去的一个小时里一直在努力让它发挥作用。任何帮助将不胜感激。 INFO: Server startup in 868 ms java.sql.SQLException: Can
假设有一些 Oracle PL/SQL 过程,它接收 IN 参数并返回 OUT 游标参数。我有一个执行此过程的 jdbc 代码: DataSource dataSource; //dataso
我正在使用 MySQL 编写一个简单的 JDBC 程序,但是只有一行代码出了什么问题。我没有看到任何错误,但下面提到的行在运行程序时显示错误 代码- ResultSet recs = psmt.exe
我是一名优秀的程序员,十分优秀!