开发者

Entities framework advanced calculated fields?

I'm looking for the best way to handle columns which are calculated on the database (not at the client). The reason for that is performance.

For example this is an invoicing program, and next to each customer I want to display a current balance (all invoice amounts minus all payment amounts). I can think of 3 ways to accomplish this:

1) adding a property to the Customer class which calculates the balance on the client side. This is obviously not efficient; this is what I curr开发者_如何学Cently do.

2) Can I use entity sql to calculate it at the db? i don't know entity sql at all so before i go learning I want to know if it's even possible / practical for this.

3) create a view on the database and map to that instead of the table

Am I missing something better? Which is best?

Thanks! -Carl

[edit] For what it's worth, option #3 seems the most practical to me. I created the view but now I encounter a problem when associating it to the original table - the problem is described here: Entities framework mapping association between view and table


You can add properties to your Customer class in a "partial class". You can perform the calculations in the additional property; just add a file to the project and define the class as partial class Customer. It will not be overwritten when you regenerate your model code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜