Example #1
0
        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);
        }
Example #2
0
        public void ColumnMapping()
        {
            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);
            categoryMapping.Column(o => o.CategoryName);
            mapping.Add(categoryMapping);

            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 }).ToArray();
        }
Example #3
0
        public void Test1()
        {
            Exception myexc = null;

            try
            {
                var mapping = new DataContextMapping <AccessNorthwind>();
                mapping.Provider = new ProviderAttribute(typeof(AccessDbProvider));

                var categoryMapping = new EntityMapping <Category>();
                categoryMapping.Column(o => o.CategoryID);
                categoryMapping.Column(o => o.CategoryName);
                categoryMapping.Column(o => o.Products);
                mapping.Add(categoryMapping);

                var mappingSource = new FluentMappingSource(o => mapping);
                //mappingSource.Add(mapping);

                var db = new AccessNorthwind(@"C:/Northwind.mdb", mappingSource);
                db.Categories.Select(o => new { o.CategoryID, o.CategoryName, Products = o.Products.ToArray() }).ToArray();
            }
            catch (Exception exc)
            {
                myexc = exc;
            }
            Assert.IsNotNull(myexc);
            Console.WriteLine(myexc.Message);
        }
Example #4
0
        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));
        }