Export (0) Print
Expand All

How to: Customize Generated Data Objects

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This topic shows how to add a custom method to a generated data class. The examples in this topic are based on the Adventure Works Sales Model. To run the code in this example, you must have already added the AdventureWorks Sales Model to your project and configured your project to use the Entity Framework. To do this, complete the procedures in How to: Manually Configure an Entity Framework Project and How to: Manually Define the Model and Mapping Files.

Example

This example defines a custom UpdateOrderTotal method for the generated SalesOrderHeader class. This custom method updates the TotalDue property based on the current values of the tax, freight, and individual item totals. This method is defined as a partial class so that it is not lost when the SalesOrderHeader class is regenerated by the Entity Framework tools.

This example modifies an order and then calls the custom UpdateOrderTotal method on SalesOrderHeader to update the TotalDue property. Because TotalDue has the StoreGeneratedPattern="computed" attribute applied in the store schema definition language (SSDL) file, this updated value is not saved to the server when SaveChanges is called. Without this attribute, an UpdateException occurs if you attempt to update a computed column on the server.

See Also

Show:
© 2014 Microsoft