Generate NHibernate POCO and mapping classes automagically

Aug 6, 2014 at 2:09 AM
hi, how to create poco class in lib, thank you
Aug 6, 2014 at 7:28 AM
Create a folder called 'Entities' in your app.

Define your class there and let it inherit from "SiteEntity" - look at this class you will see its a base class for all entities and has things like ID, CreatedOn etc.

That's all you need to do, Mr CMS does the rest for you. However if you want to have control over how it is mapped (Mr CMS auto maps entities for you) you can create another folder called 'DbConfiguration' and in there create a class called "MyEntityOverride" - it should look something like this:

public class MyEntityOverride : IAutoMappingOverride<MyEntity>
    public void Override(AutoMapping<MyEntity> mapping)
// custom mappings here
For the custom mappings you can use:

mapping.Map(x=> x.FieldName).Length(500);

This will set FieldName length to 500 instead of the usual 255 for the automapping of a string field.

If you are wanting to create a new page type of widget type that is slightly different to the above. The above address bespoke additions to Mr CMS. If you are just adding a new widget/page type let me know and I can help you through that.
Aug 6, 2014 at 8:29 AM
yes,i have a old table Student in database MrCMS, i create app School, here i want to show student list in widget. so i want to custom mapping and not include Id,CreatedOn etc.
Aug 6, 2014 at 12:06 PM
If you have an existing table you can add to nhibernate configuration by adding to your App Class:
    protected override void AppendConfiguration(NHibernate.Cfg.Configuration configuration)

You can the use this to configure whatever you like.
Aug 7, 2014 at 3:27 AM
you can give me some articles or code examples, thank you so much for your help