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

1

1 Answer 1

2
 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();
Sign up to request clarification or add additional context in comments.

1 Comment

You probably should point out that you added .ToList(); and why you did so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.