Пример #1
0
        public void TestXmlMappingSelectCustomers()
        {
            var nw = new Northwind(this.provider.New(XmlMapping.FromXml(File.ReadAllText(@"Northwind.xml"))));

            TestQuery(
                from c in db.Customers
                where c.City == "London"
                select c.ContactName
                );
        }
Пример #2
0
        public void TestNestedEntity_XmlMapped()
        {
            var provider = GetProvider().WithMapping(XmlMapping.FromXml(Nested_XmlMapped.Xml));
            var items    = provider.GetTable <Nested_XmlMapped.Employee>().ToList();

            Assert.Equal(9, items.Count);

            foreach (var item in items)
            {
                Assert.NotEqual(null, item.Address);
                Assert.NotEqual(null, item.Address.Street);
            }
        }
Пример #3
0
        public void TestBasicMapping_XmlMapped()
        {
            var provider = GetProvider().WithMapping(XmlMapping.FromXml(Basic_XmlMapped.Xml));
            var items    = provider.GetTable <Basic_XmlMapped.Customer>().ToList();

            Assert.Equal(91, items.Count);

            foreach (var item in items)
            {
                Assert.NotEqual(null, item.ID);
                Assert.NotEqual(null, item.Name);
                Assert.NotEqual(null, item.Phone);
            }
        }
Пример #4
0
        public void TestBasicMapping_XmlMapped_RuntimeType()
        {
            var provider = GetProvider().WithMapping(
                XmlMapping.FromXml(Basic_XmlMapped_RuntimeType.Xml, typeof(Basic_XmlMapped_RuntimeType.RuntimeCustomer).Assembly));
            var items = provider.GetTable <Basic_XmlMapped_RuntimeType.ICustomer>().ToList();

            Assert.Equal(91, items.Count);

            foreach (var item in items)
            {
                Assert.NotEqual(null, item.ID);
                Assert.NotEqual(null, item.Name);
                Assert.NotEqual(null, item.Phone);
            }
        }
Пример #5
0
        public void TestMultiTable_XmlMapped()
        {
            var provider = GetProvider().WithMapping(XmlMapping.FromXml(MultiTable_XmlMapped.Xml));
            var items    = provider.GetTable <MultiTable_XmlMapped.CustomerOrder>().Take(20).ToList();

            Assert.Equal(20, items.Count);

            foreach (var item in items)
            {
                Assert.NotEqual(null, item.ID);
                Assert.NotEqual(null, item.CustomerID);
                Assert.NotEqual(null, item.Name);
                Assert.NotEqual(null, item.Phone);
            }
        }
Пример #6
0
 public static QueryMapping GetMapping(string mappingId)
 {
     if (mappingId != null)
     {
         Type type = FindLoadedType(mappingId);
         if (type != null)
         {
             return(new AttributeMapping(type));
         }
         if (File.Exists(mappingId))
         {
             return(XmlMapping.FromXml(File.ReadAllText(mappingId)));
         }
     }
     return(new ImplicitMapping());
 }
Пример #7
0
        public void TestAssociation_XmlMapping_DifferenteKeys_Customer()
        {
            var provider = GetProvider().WithMapping(
                XmlMapping.FromXml(Association_XmlMapping_DifferentKeys.Xml, typeof(Association_XmlMapping_DifferentKeys.Customer).Assembly));

            var items = provider.GetTable <Association_XmlMapping_DifferentKeys.Order>()
                        .Where(o => o.Customer.ContactName.StartsWith("Maria"))
                        .ToList();

            Assert.Equal(25, items.Count);

            foreach (var item in items)
            {
                Assert.NotEqual(null, item.ID);
                Assert.NotEqual(null, item.CustomerID);
                Assert.Equal(null, item.Customer); // not retrieved, no policy
            }
        }
Пример #8
0
        /// <summary>
        /// Creates the repository. Init the provider and establish
        /// a database connection
        /// </summary>
        /// <returns></returns>
        private static DbEntityRepository CreateRepository()
        {
            DbEntityProvider dbentprovider;

            string connectionString = ConfigurationManager.AppSettings["ConnORA"];
            string MapPath          = Utils.GetMapPath("MapORA");
            string provider         = ConfigurationManager.AppSettings["ProviderORA"];

            var mapping = XmlMapping.FromXml(File.ReadAllText(MapPath));

            dbentprovider = DbEntityProvider.From(provider, connectionString, mapping, QueryPolicy.Default);

            //May not be needed for all databases,
            //some need a little kick start before serving requests
            DbInit(dbentprovider);

            return(new DbEntityRepository(dbentprovider));
        }
Пример #9
0
        public void TestAssociation_XmlMapping_DifferentKeys_Orders()
        {
            var provider = GetProvider().WithMapping(
                XmlMapping.FromXml(Association_XmlMapping_DifferentKeys.Xml, typeof(Association_XmlMapping_DifferentKeys.Customer).Assembly));

            var items = provider.GetTable <Association_XmlMapping_DifferentKeys.Customer>()
                        .Where(c => c.Orders.Count() > 1)
                        .ToList();

            Assert.Equal(88, items.Count);

            foreach (var item in items)
            {
                Assert.NotEqual(null, item.ID);
                Assert.NotEqual(null, item.ContactName);
                Assert.NotEqual(null, item.Phone);
                Assert.NotEqual(null, item.Orders);
                Assert.Equal(0, item.Orders.Count);
            }
        }