【发布时间】:2014-10-24 11:54:43
【问题描述】:
我自己有这个 SQL 查询
选择
db_accounts_last_contacts.id,
dbe_accounts_last_contacts.last_contact_date,
db_accounts_last_contacts.description,
db_accounts_last_contacts.follow_up_date,
db_accounts_last_contacts.spoke_to_person_id,
db_accounts_last_contacts.account_idFROM
db_accounts_last_contacts ,
db_companies
在哪里db_companies.id = db_accounts_last_contacts.account_id
通过db_accounts_last_contacts.last_contact_date DESC 订购
返回按 last_contact_date 排序的结果。
现在我有我的实体框架查询
var query = (from c in context.accounts_companies
select new AccountSearchResultModel()
{
LastContacted = (from calc in context.communique_accounts_last_contacts
where calc.account_id == companyId
orderby calc.last_contact_date descending
select calc.last_contact_date).FirstOrDefault()
});
但是,当我继续执行我的 ToList 时,我的结果永远不会被排序 这是我未订购的桌子
这是我使用 SQL 查询排序的列表
为什么我的实体框架查询没有提取我的 orderby?或者如果这就是为什么我总是拔出第一个?
【问题讨论】:
-
然后生成什么SQL?请进行基线调试。提供相关软件的版本号(在本例中为 EF)也可能会有所帮助。
-
TomTom 上面的查询是我的查询的 sn-p,如果我使用调试器将整个查询粘贴到 sql 中以查看 SQL,我的 sql 超过 600 行,所以不确定我是否可以发布我的SQL代码
标签: c# mysql asp.net entity-framework