2

I'm searching for the formula functionality in NHibernate with EF Code first.

Say that I have an Order with OrderLines, on the order I have my TotalAmount which could look like this

public decimal OrderTotal { return orderLines.Sum(x => x.Price); }

But I want this property to be searchable in Entity Framework so I want to do some sql code that will do this but in Sql. The result from the sql will not be set or read just be used in the search, in the memory the .net code will be used.

How can I accomplish this?

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
NPehrsson
  • 1,548
  • 18
  • 26

1 Answers1

2

EF code first doesn't have any such functionality. Even big EF is not able to do this directly as you described - you must have separate computed property in entity and model defined function for querying in EDMX (I think this should be doable in model defined function). Obviously code first doesn't have EDMX and because of that it can't define model defined function (no code fist alternative exists as I know - actually no code first alternative exists for many advanced features of EDMX like conditional mapping, query view, defining query, model defined function, function import and stored procedure mapping).

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670