Changing generated entity names?

Posts   
 
    
ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 06-Oct-2012 02:28:54   

Hello,

I am migrating an ASP.NET MVC4 Razor application from EF4 to LLBLGEN 3.5 and your runtime. The application has many layers, which would be difficult to rework/rename. I've generated an initial version of LLBLGEN Adapter, single class code, and am hoping that it would be easy to make a few changes to what is generated by your product:

1) Is it easy to change the naming of the generated entities from EntitynameEntity toBaseEntity? For example, rather than generating CustomerEntity, it would be better for us to generate BaseCustomer.

2) In our current project, we have a partial class file named AnnotatedXXXX for each generated entity, where XXXX is the name of the class. It contains a partial class of a generated class. The reason it exists is to easily attach data annotations to fields in the entity.

Can I simply copy our existing versions of these files and change their parent class to
the one that LLBLGEN created? For example,

You generated CustomerEntity.cs:

    public partial class CustomerEntity : CommonEntityBase
        {
            public long CustomerId { get; set; }
            .
            .
        }

Can I simply do the following in AnnotatedBaseCustomer.cs (change the parent class to your class)?

    [MetadataType(typeof(CustomerEntityMetadata))]
    public partial class CustomerEntity 
    {

        internal sealed class CustomerEntityMetadata
        {
            [Key]
            [Display(Name = "Title_Id", ResourceType = typeof(Resources))]
            public long CustomerId { get; set; }
        }
    }
This simply applies data annotations to the entities that you've created. 

Alternatively, I know that I can enter the data annotations using your editor, but there 
are a lot of them, so this would be a tedious task.  Is there any way I could 
import/cut-n-paste them into LLBLGEN rather than having to use the editor and enter 
them one by one by one?  After they are in your tool, then we wouldn't need to use the 
Annotated versions of these classes because LLBLGEN would simply emit them in your 
generated code.

3) In another class library, which is our business layer, we subclass from the generated entities and add our business logic/rules to each entity. Are there any special rules that we must observe when subclassing from your entities? I noticed that when you generate adapter, two-class code, there are a lot of functions generated, and our code would go into a specific region. Since we are not generating these files via LLBLGEN, I would assume that there are no special rules or sections. Is that true?

Thank you for your help! Mike

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Oct-2012 07:27:01   

Hi Mike,

ABOH wrote:

1) Is it easy to change the naming of the generated entities from EntitynameEntity toBaseEntity? For example, rather than generating CustomerEntity, it would be better for us to generate BaseCustomer.

No, that is not allowed. You could create your own subclasses and use the name you want though.

ABOH wrote:

2) In our current project, we have a partial class file named AnnotatedXXXX for each generated entity, where XXXX is the name of the class. It contains a partial class of a generated class. The reason it exists is to easily attach data annotations to fields in the entity.

Can I simply copy our existing versions of these files and change their parent class to
the one that LLBLGEN created?

Yes, you could do that.

ABOH wrote:

Alternatively, I know that I can enter the data annotations using your editor, but there are a lot of them, so this would be a tedious task. Is there any way I could import/cut-n-paste them into LLBLGEN rather than having to use the editor and enter them one by one by one? After they are in your tool, then we wouldn't need to use the Annotated versions of these classes because LLBLGEN would simply emit them in your generated code.

You could write a plugin to do that: take a file somewhere and assign attributes on your entities. See the SDK docs.

ABOH wrote:

3) In another class library, which is our business layer, we subclass from the generated entities and add our business logic/rules to each entity. Are there any special rules that we must observe when subclassing from your entities? I noticed that when you generate adapter, two-class code, there are a lot of functions generated, and our code would go into a specific region. Since we are not generating these files via LLBLGEN, I would assume that there are no special rules or sections. Is that true?

Sure. You can use your own classes. LLBLGen generates necessary constructors so the subclass can be used. You can do it by yourself if you want. You also could just write that logic/rules code into partial classes.

David Elizondo | LLBLGen Support Team
ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 07-Oct-2012 01:58:24   

Thank you for your help, David!

Mike