Dynamic dynamic automatic formatting

Does anyone know how we can automatically map dynamic components using Fluent Automapping in NHibernate?

I know that we can map normal classes as components, but couldn't figure out how to map dictionaries as dynamic components using free auto production.

thanks

+2


a source to share


1 answer


We have successfully used the following approach (with FluentNH 1.2.0.712):

public class SomeClass
{
    public int Id { get; set; }
    public IDictionary Properties { get; set; }
}

public class SomeClassMapping : ClassMap<SomeClass>
{
    public SomeClassMapping()
    {
        Id(x => x.Id);

        // Maps the MyEnum members to separate int columns.
        DynamicComponent(x => x.Properties,
                         c =>
                            {
                                foreach (var name in Enum.GetNames(typeof(MyEnum)))
                                    c.Map<int>(name);
                            });
    }
}

      

Here we have mapped all members of some Enum to separate columns, where they are all of type int . I am currently working on a scenario where we use different types for dynamic columns that look like this:

// ExtendedProperties contains custom objects with Name and Type members
foreach (var property in ExtendedProperties)
{
    var prop = property;
    part.Map(prop.Name).CustomType(prop.Type);
}

      

It also works really well.



What else am I going to figure out how to use References

instead Map

to refer to other types that have their own mapping ...

UPDATE: Unfortunately, the recommendation case is more complicated, refer to this topic on Google Groups . Shortly speaking:

// This won't work
foreach (var property in ExtendedProperties)
{
    var prop = property;
    part.Reference(dict => dict[part.Name]);
}

// This works but is not very dynamic
foreach (var property in ExtendedProperties)
{
    var prop = property;
    part.Reference<PropertyType>(dict => dict["MyProperty"]);
}

      

That's all for now.

+4


a source







All Articles