[英]How to force a conversion of string to int in a linq query
I am getting the error 我收到错误
LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法'Int32 Parse(System.String)'方法,并且该方法无法转换为商店表达式
Before my question gets called as a duplicate please read it completely. 在我的问题被重复之前,请完整阅读。 I have searched around and looked at a few solutions for this but none that seems to suit this.. 我四处搜寻并查看了一些解决方案,但似乎没有一个适合这个方案。
var query = from royalHIstory in ctx.tblRoyalHistories
join historyComment in ctx.tblRoyalHistoryComments
on royalHIstory.RoyalHistoryID equals historyComment.RoyalHistoryID
orderby royalHIstory.IndexNum ascending
where royalHIstory.InstNmbr == instnmbr
select new
{
RoyalHistoryID = royalHIstory.RoyalHistoryID,
RoyalHistoryCommentID = historyComment.RoyalHistoryCommentID,
InstNmbr = royalHIstory.InstNmbr,
IndexNum = royalHIstory.IndexNum,
RoyalIns = royalHIstory.RoyalIns,
RoyalComment = historyComment.Comment,
Name = (from memberName in ctx.tblMembers
join instruct in ctx.tblInstructors
on memberName.MemberID equals instruct.MemberID
where Convert.ToInt32(instruct.InstructorInstrNo) == royalHIstory.RoyalIns
select memberName.MemberFirstName + " " + memberName.MemberLastName).FirstOrDefault()
};
The error lands on my where clause, in the conversion 错误在转换中落在我的where子句中
where Convert.ToInt32(instruct.InstructorInstrNo) == royalHIstory.RoyalIns 其中Convert.ToInt32(instruct.InstructorInstrNo)== royalHIstory.RoyalIns
I need that conversion to happen 我需要那种转变
Convert.ToInt32(instruct.InstructorInstrNo) Convert.ToInt32(instruct.InstructorInstrNo)
and I don't know how to force it to happen 而且我不知道如何迫使它发生
you can't use 你不能使用
Convert.ToInt32(instruct.InstructorInstrNo)
in LINQ query, if you want to convert to int try this 在LINQ查询中,如果要转换为int,请尝试此操作
var query = (from royalHIstory in ctx.tblRoyalHistories
join historyComment in ctx.tblRoyalHistoryComments
on royalHIstory.RoyalHistoryID equals historyComment.RoyalHistoryID
orderby royalHIstory.IndexNum ascending
where royalHIstory.InstNmbr == instnmbr
select new {royalHIstory,historyComment }).AsEnumerable().Select(row=>new
{
RoyalHistoryID = row.royalHIstory.RoyalHistoryID,
RoyalHistoryCommentID = row.historyComment.RoyalHistoryCommentID,
InstNmbr = row.royalHIstory.InstNmbr,
IndexNum = row.royalHIstory.IndexNum,
RoyalIns = row.royalHIstory.RoyalIns,
RoyalComment = row.historyComment.Comment,
Name = (from memberName in ctx.tblMembers
join instruct in ctx.tblInstructors
on memberName.MemberID equals instruct.MemberID
where Convert.ToInt32(instruct.InstructorInstrNo) == row.royalHIstory.RoyalIns
select memberName.MemberFirstName + " " + memberName.MemberLastName).FirstOrDefault()
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.