Since partial classes have to be in the same namespace is my only option to place them in the same directy as my .edmx? If this is the case I am assuming the file name always has to be different.
Also, is there anything additional that I have to do or do I just create another partial class with the same name in the same directory and add properties/methods to it?
All parts of a partial class should be in the same namespace. Each part of a partial class should be in the same assembly or DLL, in other words you can't create a partial class in source files of a different class library project. Each part of a partial class has the same accessibility.
Partial class, interface and structure was introduced in C# 2.0. Now it is possible to split the definition of an class, interface and structure over more than one source files. Moreover the other parts of the class, struct, or interface should be defined in the same namespace or assembly.
A partial class is a special feature of C#. It provides a special ability to implement the functionality of a single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword.
Use of Partial Classes If you are working on a bigger project, splitting the files over different classes helps developers work on the same project simultaneously. If you are working on an automatically generated source, then the code can be added to the class without regenerating the source file.
The partial classes should be in the same project as the .edmx-file. (the same directory is not required).
Say your Entity Model contains an Entity Person. You can create a new file called Person.partial.cs
for your other code. You are free to use any filename for your partial classes. It is only necessary that your partial class is defined in the namespace of the Entity.
namespace MyModel{
public partial class Person {
// put your additional logic here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With