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.
having created a table thus
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]
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.
EDIT: I just added the code generation item "ADO.NET C# POCO Entity Generator" with no change in the results.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…