0
votes

I have generated entity model from my database which created entity classes.

1) Is there a way that it creates separate file for each class? 2) Can we move these classes to a different assembly? For example how can I move these classes to a different project in my solution?

I want to separate the entity model from classes and use the classes in Presentation Layer.

2

2 Answers

1
votes

You can of course create the edmx in a separate project but I don't think you can separate the classes into more than the generated default files. Note that you shouldn't attempt to edit the generated classes as these will be overwritten when updated and you can easily break stuff too.

You can, however, create a public partial class with the same namespace and class declaration as each of the Entity objects to allow you to extend the classes and add initialization / validation functions etc. allowing you to put each entity in its own class file for extending.

Updated:

All related partial classes must be in the same assembly and need to use the same namespace and class declaration as the original entity partial class in the <EntityModel>.Designer.cs. See below for example code.

namespace YourEntityNamespace
{
    public partial class YourEntity : EntityObject
    {
        // Add methods and properties to extend the entity class
    }
}
1
votes
  1. No (within the default .edmx generator) since VS's custom tool is of type IVsSingleFileGenerator and can produce only one file.
  2. Yes but you will need to customize object-layer code generation. Read here. There is a link showing how to separate the model and generated classes between projects.

@Chris, partial classes cannot be split across assemblies. There are many questions/answers here about this.