且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在LINQ中将字符串转换为int到实体?

更新时间:2023-02-03 08:28:49

在LINQ之外进行转换:

Do the conversion outside LINQ:

var idInt = Convert.ToInt32(id);
var query = (from p in dc.CustomerBranch
             where p.ID == idInt 
             select new Location()
             {
                 Name      = p.BranchName,
                 Address   = p.Address,
                 Postcode  = p.Postcode,
                 City      = p.City,
                 Telephone = p.Telephone
             }).First();
return query;