C#/ ASP.NET的lambda转换 [英] C#/ASP.NET lambda conversion
问题描述
不知怎的,当我回到这个我的看法:
Somehow when I return this to my view:
return View(db.Properties.ToList());
我得到的3个属性,其中之一有俄勒冈州。
I get 3 properties, one of which has the location value of "Oregon".
但在声明如下另一种方法:
But in another method declared like this:
public ViewResult Browse(string location)
{
return View(db.Properties.Where(p => p.location == location).ToList());
}
我得到0的属性。
I get 0 properties.
我怀疑字符串位置是越来越转化为一些奇怪的地方,但我不知道用什么方式将它转换得到。当我用==俄勒冈州'取代拉姆达'==位置'我仍然得到0的属性。
I suspect the string "location" is getting converted to something strange somewhere, but I'm not sure in what way it would be getting converted. When I replace the lambda '== location' with '== "Oregon"' I still get 0 properties.
我该如何解决这个问题?
How do I fix this?
此外,反正是有看到,被用于调试创建的中间SQL?
Also, is there anyway to see the intermediate SQL that gets created for debugging purposes?
编辑:这是使用实体框架
This is using entity framework.
编辑:我收到略有不同的结果了。看来传入位置字符串是空的(即使我看到它的URL)。我在改写一切,贴吧:
I'm getting slight different results now. It appears the incoming location string is empty (even though I see it in the URL). I have rewritten everything and posted it at:
推荐答案
我不能复制这一点 - 我尝试以下...
I can't replicate this - I tried the following...
public ActionResult Index()
{
var db = new ORMTestEntities();
var oneprop = db.Properties.Where(p => p.location == "Oregon").ToList();
ViewBag.Oneprop = oneprop;
return View(db.Properties.ToList());
}
public ActionResult Index2()
{
var db = new ORMTestEntities();
var oneprop = db.Properties.Where(p => p.location == "Oregon").ToList();
ViewBag.Oneprop = oneprop;
return View("Index",db.Properties.Where(p => p.location == "Oregon").ToList());
}
这两个工作预期。
both of which work as expected.
在创建了一个表从而
CREATE TABLE [dbo].[Properties](
[Id] [int] IDENTITY(1,1) NOT NULL,
[location] [varchar](50) NULL,
[otherthing] [varchar](50) NULL,
CONSTRAINT [PK_Properties] PRIMARY KEY CLUSTERED
(
[Id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
这是使用外的开箱EF模型生成 - 没有T4模板,也没有添加code代项目或其他任何东西。我建议你从头开始,并在同一时间重新打造一件事,看看那里出了问题。
This is using the out-of-the-box EF model generation - no T4 templates, no "Add Code Generation Item" or anything else. I'd suggest you start from scratch and re-build one thing at a time to see where it goes wrong.
编辑:我刚添加的code代项目ADO.NET C#POCO实体发生器,在结果没有改变。
I just added the code generation item "ADO.NET C# POCO Entity Generator" with no change in the results.
要回答你的问题的第二部分,为了看数据库查询最简单的就是挂钩EFProf 的http:/ /efprof.com/ - 30天的试用期应为你工作。
To answer the second part of your question, in order to see the DB queries the easiest thing is to hook up EFProf http://efprof.com/ - the 30 day trial should work for you.
这篇关于C#/ ASP.NET的lambda转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!