0

I have a linq query, and want to assign string value to a string property, which in dependent on another int property value. I have saved int value in database, and now want to get appropriate string value for the saved integer value. Below is my query..

 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();

I got below error

The entity or complex type 'PMISModel.ProjectSetup' cannot be constructed in a LINQ to Entities query

Shahid Iqbal
  • 1,883
  • 8
  • 26
  • 50
  • 1
    You cannot do that onto a mapped entity.Check this,http://stackoverflow.com/questions/5325797/the-entity-cannot-be-constructed-in-a-linq-to-entities-query – Sajeetharan Dec 02 '14 at 06:01

1 Answers1

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();
Shahid Iqbal
  • 1,883
  • 8
  • 26
  • 50