Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A couple ideas:</p> <ol> <li><p>Why not use <a href="http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx" rel="nofollow">Code First</a>? That way, you can put business logic (e.g., calculated properties) right in your entity class.</p> <p>Example</p> <pre><code>public partial class SalesOrderLine { public int ID { get; set; } public int SalesOrderID { get; set; } public int ProductID { get; set; } private decimal _unitPrice; public decimal UnitPrice { get { return _unitPrice; } set { if (value == _unitPrice) return; _unitPrice = value; CalculateExtendedPrice(); } } private decimal _quantity; public decimal Quantity { get { return _quantity; } set { if (value == _quantity) return; _quantity= value; CalculateExtendedPrice(); } } public decimal ExtendedPrice { get; set; } public virtual Product Product { get; set; } public virtual SalesOrder SalesOrder { get; set; } private void CalculateExtendedPrice() { ExtendedPrice = UnitPrice * Quantity; } } </code></pre></li> <li><p>If Code First is not an option, what about making your entity a <a href="http://msdn.microsoft.com/en-us/library/wa80x488%28v=vs.100%29.aspx" rel="nofollow">partial class</a> (if it is not already) and putting your business logic in a separate code file (but with the same class name). This way, your main code file will get overwritten when you generate, but your secondary code file will remain. This is the usual way to deal with generated code.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload