使用數據庫TABLE名爲Costcenter。 我試圖在CostcenrCode只有三個數字字符的下拉列表中顯示Costcenters。我試圖在ASP.Net WF應用程序的VIEW上執行此操作。現在我已經將它移到了使用LINQ to SQL的DataAccess查詢中。我有點困惑,如何在LINQ查詢中返回String。我在最後選擇cc來填充數據庫表中的所有Costcenter。但我只需要拉一個就好(例如100而不是F.C56)。RegEx與LINQ to SQL查詢過濾要在UI上顯示的數據
我的數據訪問代碼如下:
public static IEnumerable<Costcenter> GetAllCostcentersByCountryCompanyProfitcenterYear(short year, int companyID)
{
List<Costcenter> costcenters = new List<Costcenter>();
using (var context = new CostReportEntities())
{
costcenters = (from cc in context.Costcenters
join company in context.Companies on cc.CompanyID equals company.CompanyID
where cc.Year == year && cc.CompanyID == companyID
select cc).ToList();
}
return costcenters;
}
我一直在尋找幾個帖子在這裏,但因爲我在LINQ是新來的SQL不能把任何東西在一起。
您不能將linq的Regex.IsMatch用於SQL。 – 2013-02-11 16:21:18
您使用的是什麼RDMS? SQL Server,Oracle,....? – 2013-02-12 09:09:41