ihavenokia ihavenokia - 23 days ago 6
ASP.NET (C#) Question

How to implement partial class in MVC4?

I have a class Employee.cs that was autogenerated by EntityFramework when i connected to a database, now i want to implement a partial class but I can't use "Employee.cs" name for that class because it already exists. Can I give other name to it and it will work? Can you explain how the compiler will know that there is another partial class of Employee.cs?

Answer

You can give the file whatever name you want like Employee.custom.cs but you have to call the class in it Employee in the same namespace as the Employee class in the other file, also with a partial modifier, and you should be good to go.

The compiler just gathers all the partial classes with the same name and compiles it into one class per name.