LinQ如何将像1这样的整数更改为字符串001 [英] LinQ how to change a integer like 1 to string 001
本文介绍了LinQ如何将像1这样的整数更改为字符串001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库中有一个包含四列的表:
I have a table in my database with four columns:
string: year
string: weeknr
int: number
在其他表中,我将这些列作为字符串组合到yywwnnn
中.
In other tables I combine these columns into yywwnnn
as a string.
数字列是标识列.
现在,我想从一个表中检索一些要与上述表连接的记录.
Now I want to retrieve some records from a table that I want to join with the mentioned table.
类似:
from R in db.Requests
join RN in db.RequestNumbers on R.RequestNumber equals (RN.Year + RN.Weeknr + RN.Number)
但是RN.Number当然是一个整数,我需要它是一个3位数的字符串.
But of course RN.Number is a integer and I need it to be a 3 digit string.
如此:
16 07 1 ==> 1607001
16 07 10 ==> 1607010
16 07 100 ==> 1607100
so:
16 07 1 ==> 1607001
16 07 10 ==> 1607010
16 07 100 ==> 1607100
我已经尝试过了:
from R in db.Requests
join RN in db.RequestNumbers on R.RequestNumber equals (RN.Year + RN.Weeknr + (RN.Number.toString().PadLeft(3,char.Parse("0")))
但是PadLeft无法识别.
还有其他解决方案吗?
But PadLeft is not recognized.
Is there any other solution to this?
这是完整的方法:
public List<RequestList> getMyRequests(string userID)
{
var result = (from R in db.Requests
join MT in db.MainTorsList on R.Category equals MT.MainTorsListID into MTL
from MT in MTL.DefaultIfEmpty()
join ST in db.SubTorsList on R.RequestType equals ST.SubTorsListID into STL
from ST in STL.DefaultIfEmpty()
join S in db.StatusList on R.RequestStatus equals S.StatusListID into SL
from S in SL.DefaultIfEmpty()
join RN in db.RequestNumber on R.RequestNumber equals RN.Year + RN.Week + (RN.Number.ToString().PadLeft(3, char.Parse("0"))) into RNL
from RN in RNL.DefaultIfEmpty()
where R.CreatedBy == userID && RN.Removed == false
select new
{
RequestID = R.RequestID,
RequestDate = R.CreatedOn,
RequestNumber = R.RequestNumber,
Category = MT.Name,
RequestType = ST.Name,
Description = R.RequestDescription,
Status = S.Name,
Options = ""
}
);
List<RequestList> requests = (List<RequestList>)result.ToList().ToNonAnonymousList(typeof(RequestList));
return requests;
}
错误消息:
Additional information: LINQ to Entities does not recognize the method 'System.String PadLeft(Int32, Char)' method, and this method cannot be translated into a store expression.
推荐答案
查看全文