2014-12-02 126 views
0

我有一個linq query,並希望將字符串值分配給字符串屬性,該字符串屬性依賴於另一個int屬性值。我在數據庫中保存了int值,現在想要爲保存的整數值獲取適當的字符串值。下面是我的查詢..基於Linq查詢的整數屬性值爲字符串屬性指定值

var data = db.ProjectSetups.Select(c => new ProjectSetup 
       { 
        ProjectId = c.ProjectId, 
        Name = c.Name, 
        NameArabic = c.NameArabic, 
        StartDate = c.StartDate, 
        EndDate = c.EndDate, 
        Date = c.Date, 
        StringType = (c.Type.ToInt32() == 1 ? "Development" : "Rental").ToString(), 
        StringStatus = (c.Status == 1 ? "InProgress" : 
        c.Status == 2 ? "Completed" : 
        c.Status == 3 ? "Dividend" : "Closed"), 
        LandArea = c.LandArea, 
        SaleAmount = c.SaleAmount 

       }).ToList(); 

我有以下錯誤

實體或複雜類型 'PMISModel.ProjectSetup' 不能在LINQ構建以查詢實體

+1

你不能這樣做到一個映射entity.Check這,http://stackoverflow.com/questions/5325797/the-entity-cannot-be-constructed-in-a-linq-to-entities-query – Sajeetharan 2014-12-02 06:01:17

回答

1
var data = db.ProjectSetups.ToList(); 
    data = data.Select(c => new ProjectSetup 
         { 
          ProjectId = c.ProjectId, 
          Name = c.Name, 
          NameArabic = c.NameArabic, 
          StartDate = c.StartDate, 
          EndDate = c.EndDate, 
          Date = c.Date, 
          StringType = (c.Type.ToInt32() == 1 ? "Development" : "Rental").ToString(), 
          StringStatus = (c.Status == 1 ? "InProgress" : 
          c.Status == 2 ? "Completed" : 
          c.Status == 3 ? "Dividend" : "Closed"), 
          LandArea = c.LandArea, 
          SaleAmount = c.SaleAmount 

         }).ToList(); 
+0

你可能應該點那個你添加了'.ToList();'爲什麼你這麼做。 – Enigmativity 2014-12-02 07:33:38