Usage

  1. Reference ALinq.FluentMappingSource.dll assembly (for ALinq users), or System.Data.Linq.FluentMappingSource.dll (for Linq to SQL users).
  2. Import ALinq.Mapping namespace.
  3. Create a strong type mapping source inheritance from FluentMappingSource.

Example

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

            mapping.Table(o => o.Products, ProdcutTableName)
                    .PrimaryKey(o => o.ProductID)
                    .Column(o => o.ProductName)
                    .Column(o => o.CategoryID)
                    .Association(o => o.Category, o => o.CategoryID, o => o.CategoryID);

            if (func != null)
                func(mapping);
        });
    }
}
var mappingSource = new NorthwindMappingSource();
var db = new NorthwindDatabase(mappingSource) { Log = Console.Out };
var categories = db.Categories.ToArray();

Last edited Apr 16, 2013 at 4:37 AM by ansiboy, version 2

Comments

No comments yet.