Reputation: 25
In a LINQ to SQL class you get the option to View Code of any entity you drag in the design surface. This creates a Partial Class.
Lets say we have an Employee Entity and I create a partial class Employee. What can I use that partial class for? Is it to add Employee methods such as DoWork()?
Do I need to declare any variables that are in the table? (In case of Employee: Name, Surname etc) If so, how do I make the connection between the data present in the Employee record to the class?
Upvotes: 0
Views: 38
Reputation: 4809
partial class is used in EF in order to allow you to make changes and additions to entity classes in a file that is not auto generated. Changes in and auto-generated file might be overridden when updating db context. The use of your own files which extend the partials defined in the auto-generated files prevents that. this also allows you to add implementation to partial methods defined in that partial class, most typically event handlers.
using a partial class in the same name space is very much similar to work inside the other part of class it extends, and it simply allows you to write one class in more than one file. for more information:
https://msdn.microsoft.com/en-us/library/wa80x488.aspx
Upvotes: 1