Mapping Source

class NorthwindMappingSource : FluentMappingSource
{
    public NorthwindMappingSource(Action<DatabaseMapping<NorthwindDatabase>> func = null)
    {
        Map<NorthwindDatabase>(mapping =>
        {
            mapping.ProviderType = typeof(AccessDbProvider);
            mapping.Table(o => o.Categories, "Categories")
                    .PrimaryKey(o => o.CategoryID)
                    .Column(o => o.CategoryName)
                    .Column(o => o.Description);

            if (func != null)
                func(mapping);
        });
    }
}

Append A Column

var mappingSource = new NorthwindMappingSource(mapping =>
{
    mapping.Table(o => o.Categories, "Categories")
            .Column(o => o.Products);
});

Append A Table

var mappingSource = new NorthwindMappingSource(mapping =>
{
    mapping.Table(o => o.Products, "Products")
            .PrimaryKey(o => o.ProductID)
            .Column(o => o.ProductName);
});

Remove A Column

var mappingSource = new NorthwindMappingSource(mapping =>
{
    var table = mapping.GetTable(typeof(Category));
    var column = table.RowType.GetColumn(typeof(Category).GetProperty("CategoryName"));
    table.RowType.Columns.Remove(column);
});

Remove A Table

var mappingSource = new NorthwindMappingSource(mapping =>
{
    var table = mapping.GetTable(typeof(Category));
    mapping.Tables.Remove(table);
});

Last edited May 15, 2013 at 3:50 PM by ansiboy, version 2

Comments

No comments yet.