This project is read-only.

Logic of MapBuilder

Mar 25, 2012 at 12:08 PM

Why MapBuilder register map rules inside? Why can not I create more tnan one map for a entity with a different set of fields, and then register it to MapRepository, and then use in queries?

Mar 26, 2012 at 12:05 AM

Hi Vitidev,

It would be fairly easy to create optional "named" mappings.  The MapBuilder could have an optional "name" parameter to accomplish this.  Then there could be an optional Query<T> method to utilize this name, for example:

        private static void Build_Order_Default()
        {
            _builder.BuildColumns()
                .For(o => o.ID)
                    .SetPrimaryKey()
                    .SetAutoIncrement();

            _builder.BuildRelationships();
        }

        private static void Build_Order_Simple()
        {
            _builder.BuildColumns("SimpleMap")
                .For(o => o.ID)
                    .SetPrimaryKey()
                    .SetAutoIncrement();

            _builder.BuildRelationships();
        }

        private static void Build_Order_Simple()
        {
            _builder.BuildColumns("Fullmap")
                .For(o => o.ID)
                    .SetPrimaryKey()
                    .SetAutoIncrement();

            _builder.BuildRelationships();
        }

// Default mapping
var orders = db.Query().ToList();

// Named mapping
var orders = db.Query().Mappings("SimpleMap").ToList();

// Named mapping
var orders = db.Query().Mappings("FullMap").ToList();

Mar 26, 2012 at 12:11 AM

Another alternative would be to allow mapping columns on-the-fly (at query time).  For example:

// Specify columns at query time
var orders = db.Query()
        .Select(o => o.ID, o => o.OrderDate.FromColumn("ORDER_DATE"))
        .From("OrdersView")
        .Where(o => o.OrderDate > DateTime.Now)
        .ToList();