使用MVC3 VS2010和SQL Server 2008 Express 我试图基于两个SQL服务器表并显示结果。 一个表是客户表,另一个表是代理。它们在客户端表中具有相同的ClientAgentID,在代理表中具有相同的ID。代理程序日志,应该能够看到分配给代理程序的客户端。如果你有任何想法来做到这一点,请帮助我。到目前为止,我正在尝试在客户端控制器中进行筛选,这里是我所拥有的,但是我得到的信息是标题中的。LINQ to Entities不能识别方法'System.String ToString(Int32)'方法,并且此方法不能转换为存储表达式
public ActionResult Index()
{
//This displays all the clients not filtered by the Agent ID number
//var clientItems = db.MVCInternetApplicationPkg;
//return View(clientItems.ToList());
//Trying to filter by the agent name given in the login page then finding
//the agent ID
var getAgentID = from a in db.AgentsPkg
where a.AgentLogin == User.Identity.Name
select a.ID;
var clientItems = from r in db.MVCInternetApplicationPkg
where Convert.ToString(r.ClientAgentID)
== Convert.ToString(getAgentID)
select r;
//THIS IS THE LINE OF CODE THAT SHOWS THE ERROR MESSAGE
return View(clientItems.ToList());
}
这是我第一个音乐商店之后的MVC项目,所以我愿意学习并接受任何帮助或建议。 干杯
这是我最终使用的解决方案。任何反馈。如果这是一个很好的方法,将不胜感激
public ActionResult Index()
{
var innerJoint = from agents in db.AgentsPkg where agents.AgentLogin == User.Identity.Name
join clients in db.MVCInternetApplicationPkg on agents.ID equals clients.ClientAgentID
select clients;
return View(innerJoint.ToList());
}
[LINQ to Entities可能重复无法识别方法'Int32](http://stackoverflow.com/questions/3316615/linq-to-entities-does-not-recognize-the-method-int32) –
AgentsPkg和MVCInternetApplicationPkg之间是否定义了外键? – Merenzo
@Merenzo在SQL数据库中定义了一个外键,但在MVC中没有引用外键的地方 – WillNZ