Association Mapping

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, o => { o.DbType = "Binary"; o.CanBeNull = true;
                                                   o.UpdateCheck = UpdateCheck.Never; })
                    .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);
        });
    }
}

Inheritance Mapping

class NorthwindMappingSource : FluentMappingSource
{
    public NorthwindMappingSource(Action<DatabaseMapping> func = null)
    {
        this.Map<NorthwindDatabase>(mapping =>
        {
            mapping.ProviderType = typeof(AccessDbProvider);
            mapping.Name = typeof(NorthwindDatabase).Name;
            mapping.Table(o => o.Contacts, "Contacts", o => { o.InheritanceCode = "Unknow";  
                                                              o.IsInheritanceDefault = true; })
                    .PrimaryKey(o => o.ContactID, o => { o.Storage = "_ContactID"; })
                    .Column(o => o.ContactType, o => o.IsDiscriminator = true)
                    .Column(o => o.CompanyName)
                    .Column(o => o.Phone)
                    .Column(o => o.GUID)
                    .Inheritance<FullContact>()
                    .Column(o => o.ContactName)
                    .Column(o => o.ContactTitle)
                    .Column(o => o.Address)
                    .Column(o => o.City)
                    .Column(o => o.Region)
                    .Column(o => o.PostalCode)
                    .Column(o => o.Country)
                    .Column(o => o.Fax)
                    .Inheritance<SupplierContact>()
                    .Column(o => o.HomePage)
                    .Inheritance<EmployeeContact>()
                    .Column(o => o.PhotoPath)
                    .Column(o => o.Photo)
                    .Column(o => o.Extension)
                    .Inheritance<CustomerContact>()
                    .Inheritance<ShipperContact>();

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

Last edited Apr 17, 2013 at 7:41 AM by ansiboy, version 1

Comments

No comments yet.