简体   繁体   English

使用Entity Framework的Linq查询没有结果

[英]Linq query with Entity Framework yields no result

I am doing a query with linq and entity framework. 我正在用linq和实体框架进行查询。 The database I'm using is Oracle. 我正在使用的数据库是Oracle。 Here is the code : 这是代码:

Entities bdd = contextWrapper.GetContext();

data = (from table in bdd.COP_PRDTICSOURES
        where (table.IDTTIC==ticketId && table.IDTPRD==productId)
        select table).AsEnumerable();

When I look at the variable bdd.COP_PRDTIC_SOURES using a debugger, it contains an entry matching my two criteria. 当我使用调试器查看变量bdd.COP_PRDTIC_SOURES ,它包含一个符合我的两个条件的条目。 However, after the execution of the query, the data variable contains no result. 但是,执行查询后, data变量不包含任何结果。

Is there something wrong with my syntax ? 我的语法有问题吗?

Some additional information: 一些其他信息:

  • The entity i'm looking for isn't commited in the database when I perform this query. 执行此查询时,我要查找的实体未在数据库中提交。 It's created before in the same transaction. 它是在同一事务中之前创建的。
  • I use a foreach on the data after, so it's not a problem of lazy loading. 之后,我在数据上使用了foreach ,因此这不是延迟加载的问题。

AsEnumerable does not load data from DB. AsEnumerable不会从数据库加载数据。 Calling it you are not executing the actual query, just changing how it is going to be executed in its entirety. 调用它并不是在执行实际查询,而只是更改整个查询的执行方式。

Use ToArray or ToList instead to load data explicitly. 改用ToArrayToList显式加载数据。 Or call foreach on this collection. 或在此集合上调用foreach

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM