public void GetDataContextMapping() { var mapping = new DataContextMapping <AccessNorthwind>(); mapping.Provider = new ProviderAttribute(typeof(AccessDbProvider)); var categoryMapping = new EntityMapping <Category>(); categoryMapping.TableAttribute = new TableAttribute { Name = "Categories" }; categoryMapping.Column(o => o.CategoryID, o => o.PrimaryKey()); categoryMapping.Column(o => o.CategoryName, o => o.NeverUpdateCheck()); categoryMapping.Association(o => o.Products, o => o.Keys("CategoryID", "CategoryID")); mapping.Add(categoryMapping); var mappingSource = new FluentMappingSource(o => mapping); //mappingSource.Add(mapping); //mapping = mappingSource.GetDataContextMapping<AccessNorthwind>(); //Assert.IsNotNull(mapping); //var mapping1 = mappingSource.GetDataContextMapping<DataContext>(); //Assert.IsNull(mapping1); }
public void AssociationMapping() { var mapping = new DataContextMapping <AccessNorthwind>(); mapping.Provider = new ProviderAttribute(typeof(AccessDbProvider)); var categoryMapping = new EntityMapping <Category>(); categoryMapping.TableAttribute = new TableAttribute { Name = "Categories" }; categoryMapping.Column(o => o.CategoryID, new ColumnAttribute { IsPrimaryKey = true }); categoryMapping.Column(o => o.CategoryName); categoryMapping.Association(o => o.Products, new AssociationAttribute { OtherKey = "CategoryID" }); mapping.Add(categoryMapping); var productMapping = new EntityMapping <Product>(); productMapping.TableAttribute = new TableAttribute { Name = "Products" }; productMapping.Column(o => o.ProductID, o => o.PrimaryKey()); productMapping.Column(o => o.ProductName, o => o.NeverUpdateCheck()); productMapping.Column(o => o.CategoryID, o => o.NeverUpdateCheck()); productMapping.Association(o => o.Category, o => o.Keys("CategoryID", "CategoryID").Storage("_Category")); mapping.Add(productMapping); var mappingSource = new FluentMappingSource(o => mapping); //mappingSource.Add(mapping); var db = new AccessNorthwind(@"C:/Northwind.mdb", mappingSource) { Log = Console.Out }; db.Categories.Select(o => new { o.CategoryID, o.CategoryName, o.Products }).ToArray(); db.Categories.ToArray(); db.Products.ToArray(); var products = db.Products.ToList(); products.ForEach(o => Console.WriteLine(o.Category)); }