KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to figure out the best way to do what I thought would be easy. I have a database model called Line that represents a line in an invoice. It looks roughly like so: public partial class Line { public Int32 Id { get; set; } public Invoice Invoice { get; set; } public String Name { get; set; } public String Description { get; set; } public Decimal Price { get; set; } public Int32 Quantity { get; set; } } This class is generated from the db model. I have another class that adds one more property: public partial class Line { public Decimal Total { get { return this.Price * this.Quantity } } } Now, from my customer controller I want to do something like this: var invoices = ( from c in _repository.Customers where c.Id == id from i in c.Invoices select new InvoiceIndex { Id = i.Id, CustomerName = i.Customer.Name, Attention = i.Attention, Total = i.Lines.Sum( l => l.Total ), Posted = i.Created, Salesman = i.Salesman.Name } ) But I can't thanks to the infamous The specified type member 'Total' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. What is the best way to refactor this so that it works? I have tried LinqKit, i.Lines.AsEnumerable(), and putting i.Lines in my InvoiceIndex model and having it calculate the sum for the view. That last solution 'works' but I cannot sort on that data. What I want to be able to do in the end is var
Tags (comma-separated)
Save Edits
Cancel