![](/img/trans.png)
[英]LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method
[英]LINQ to Entities does not recognize the method 'System.String getFullname(System.String, System.String)'
我试图从我的控制器操作方法中调用业务模型类的静态方法,但我失败了。 请我真的需要您的帮助。 谢谢
public ActionResult Index()
{
var model =
_db.members
.Include(m =>m.homeTownCity)
.Include(m => m.currentCity)
.OrderBy(m => m.fname)
.ThenBy(m => m.lname)
.Select(m => new MembersListViewModel
{
homeTown = m.homeTownCity.Name,
currentCity = m.currentCity.Name,
//Calling a business class static method
Name= MemberManagement.getFullname(m.lname,m.fname),
spoken = m.spoken,
hasPosted = m.posts.Count()
});
return View(model);
}
public class MemberManagement
{
public static string getFullname( string fname,string lname) {
string fullname = fname + " " + lname;
return fullname;
}
}
这是因为您的静态方法不能转换为SQL并不能由实体框架执行。
首先将您的成员拉下来作为列表,然后进行选择,因为这将由服务器而不是在SQL级别执行。
var members =
_db.members
.Include(m =>m.homeTownCity)
.Include(m => m.currentCity)
.OrderBy(m => m.fname)
.ThenBy(m => m.lname).ToList();
var model = members.Select(m => new MembersListViewModel
{
homeTown = m.homeTownCity.Name,
currentCity = m.currentCity.Name,
//Calling a business class static method
Name= MemberManagement.getFullname(m.lname,m.fname),
spoken = m.spoken,
hasPosted = m.posts.Count()
}).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.