예제 #1
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();
        }
예제 #2
0
        public void Attach()
        {
            var db        = new AccessNorthwind("C:/Northwind.mdb");
            var shipperID = db.Shippers.Max(o => o.ShipperID);
            var shipper   = new Shipper {
                ShipperID = shipperID
            };

            db.Shippers.Attach(shipper, true);
            var changeSet = db.GetChangeSet();

            Exception exc = null;
            var       db2 = new AccessNorthwind("C:/Northwind.mdb");

            try
            {
                db2.Shippers.Attach(shipper);
            }
            catch (Exception e)
            {
                exc = e;
            }
            Assert.IsNotNull(exc);
            Console.WriteLine(exc.GetType());

            //db.Shippers.Detach(shipper);
            db2.Shippers.Attach(shipper);
        }
예제 #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);
        }
예제 #4
0
        public void InsertMethod()
        {
            var contact = new SqlMethod();
            var db      = new AccessNorthwind("C:/Northwind.mdb");

            db.SqlMethods.InsertOnSubmit(contact);
            db.SubmitChanges();
            Assert.AreEqual(NorthwindDatabase.SqlMethodAction.InsertContact, db.SqlAction);
        }
예제 #5
0
        public void Test2()
        {
            var mappingSource = new FluentMappingSource(o => new NorthwindMapping());
            var db            = new AccessNorthwind("C:/Northwind.mdb", mappingSource)
            {
                Log = Console.Out
            };

            db.Employees.ToArray();
        }
예제 #6
0
        public void NorthwindMappingTest()
        {
            var mappingSource = new FluentMappingSource(o => new NorthwindMapping());
            var db            = new AccessNorthwind("C:/Northwind.mdb", mappingSource)
            {
                Log = Console.Out
            };

            db.Contacts.OfType <FullContact>().ToArray();
        }
예제 #7
0
        public void TestInitialize()
        {
            var xmlMapping = XmlMappingSource.FromStream(typeof(SQLiteTest).Assembly.GetManifestResourceStream("Test.Northwind.Access.map"));

            db = new AccessNorthwind("C:/Northwind.mdb");
            //db = new AccessNorthwind("C:/Northwind.mdb", xmlMapping);
            //db = new SQLiteNorthwind("C:/Northwind.db3");
            //db = new MySqlNorthwind(MySqlNorthwind.CreateConnection("root", "test", "Northwind", "localhost", 3306).ConnectionString);
            db.Log = Console.Out;
            //this.mappingSource = new DynamicMappingSource()
        }
예제 #8
0
        public void CreateProcedure1()
        {
            var db = new AccessNorthwind("C:/Northwind.mdb");
            //db.ExecuteCommand("Drop PROCEDURE GetCategories");
            var command = @"Create PROCEDURE GetCategories
                            AS
                            Select CategoryID, CategoryName, Description
                            From Categories";

            db.ExecuteCommand(command);
        }
예제 #9
0
        public void AccessConnectionTest()
        {
            var builder = new OleDbConnectionStringBuilder()
            {
                DataSource = "C:/Northwind.mdb",
                Provider   = "Microsoft.Jet.OLEDB.4.0",
            };
            var conn    = new OleDbConnection(builder.ToString());
            var context = new AccessNorthwind(conn);

            TestConnection(context, conn);
        }
예제 #10
0
        public void CompileTest()
        {
            var CustomersByCity =
                ALinq.CompiledQuery.Compile <NorthwindDatabase, string, IEnumerable <SimpleCustomer> >((db, city) =>
                                                                                                       from c in db.Customers
                                                                                                       where c.City == city
                                                                                                       select new SimpleCustomer {
                ContactName = c.ContactName
            });
            var context = new AccessNorthwind("C:/Northwind.mdb");
            var result  = CustomersByCity(context, "London").ToList();

            Assert.IsTrue(result.Count > 0);
        }
예제 #11
0
        public void ObjectIdentity()
        {
            var db = new AccessNorthwind("C:/Northwind.mdb")
            {
                Log = Console.Out
            };
            var shipperID = db.Shippers.Max(o => o.ShipperID);

            Assert.IsTrue(shipperID != 0);
            var shipper1 = db.Shippers.Where(o => o.ShipperID == shipperID).Single();
            var shipper2 = db.Shippers.OrderByDescending(o => o.ShipperID).First();

            Assert.AreSame(shipper1, shipper2);
        }
예제 #12
0
파일: Temp.cs 프로젝트: yousaf2k/ALinq
        public void Test1()
        {
            var db = new AccessNorthwind("C:/Northwind.mdb")
            {
                Log = Console.Out
            };

            db.DoTransacte(delegate()
            {
                db.Customers.Update(o => new Customer {
                    CompanyName = "XXXX"
                }, o => o.CustomerID == "kkkkk");
                db.Customers.Delete(o => o.CustomerID == "aaaaa");
            });
        }
예제 #13
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));
        }
예제 #14
0
        public void GetCreateTableCommandTest()
        {
            LicenseManager.CurrentContext.SetSavedLicenseKey(typeof(ALinq.Access.AccessDbProvider), "ansiboy" + Environment.NewLine + "QO77626437CFA2FE9E");
            //var obj = LicenseManager.CreateWithContext(typeof (ALinq.Access.AccessDbProvider), new LicenseContext());
            //Console.Write(obj);
            var mapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Access.map"));
            var db      = new AccessNorthwind("c:/nrothwind.mdb", mapping);

            var target = new DatabaseSqlBuilder((SqlProvider)db.Provider);

            MetaTable table = db.Mapping.GetTable(typeof(Category));
            //string expected = string.Empty;
            string actual;

            actual = target.GetCreateTableCommand(table);
            //Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
            Console.WriteLine(actual);
        }
예제 #15
0
파일: AccessTest.cs 프로젝트: zyj0021/ALinq
        public static void Initialize(TestContext testContext)
        {
            var type     = typeof(SQLiteTest);
            var path     = type.Module.FullyQualifiedName;
            var filePath = Path.GetDirectoryName(path) + @"\ALinq.Access.lic";

            //File.Copy(@"E:\ALinqs\ALinq1.8\Test\ALinq.Access.lic", filePath);

            writer = new StreamWriter("c:/Access.txt", false);
            var database = new AccessNorthwind("C:/Northwind.mdb")
            {
                Log = writer
            };

            if (!database.DatabaseExists())
            {
                database.CreateDatabase();
                database.Connection.Close();
            }
        }
예제 #16
0
        public void TranslateTest()
        {
            var db = new AccessNorthwind("C:/Northwind.mdb")
            {
                Log = Console.Out
            };
            var command = db.GetCommand(db.Products.OrderBy(o => o.ProductName));

            command.Connection.Open();
            Console.WriteLine(command.CommandText);
            var reader = command.ExecuteReader();

            var items = db.Translate <P>(reader).ToList();

            foreach (var item in items)
            {
                Console.WriteLine(item.ProductName + " " + item.ID);
            }

            command.Connection.Close();
        }
예제 #17
0
        public void Test1()
        {
            var db = new AccessNorthwind("C:/Northwind.mdb");

            var q       = db.Users.Where(o => o.ID < 100);
            var command = db.GetCommand(q);

            Console.WriteLine(command.CommandText);
            command.Connection.Open();
            var reader = command.ExecuteReader();

            try
            {
                var items = db.Translate <T>(reader);
                foreach (var item in items)
                {
                    Console.Write(item.ID);
                }
            }
            finally
            {
                db.Connection.Close();
            }
        }
예제 #18
0
 public Database1()
     : base(AccessNorthwind.CreateConnection(@"C:/Northwind.mdb"))
 {
 }
예제 #19
0
파일: AccessTest.cs 프로젝트: zyj0021/ALinq
 protected DbConnection CreateConnection()
 {
     return(AccessNorthwind.CreateConnection("C:/Northwind.mdb"));
 }
예제 #20
0
        public void SetDataContextTest()
        {
            var db    = new AccessNorthwind("C:/Northwind.mdb");
            var order = db.Orders.First();

            Assert.IsNotNull(order.DataContext);

            var customer = db.Customers.SingleOrDefault(o => o.CustomerID == "MCSFT");

            if (customer != null)
            {
                Assert.AreEqual(db, customer.DataContext);

                db.Customers.DeleteOnSubmit(customer);
                db.SubmitChanges();
                //Assert.AreEqual(null, customer.DataContext);
            }

            var newCustomer = new Customer
            {
                CustomerID   = "MCSFT",
                CompanyName  = "Microsoft",
                ContactName  = "John Doe",
                ContactTitle = "Sales Manager",
                Address      = "1 Microsoft Way",
                City         = "Redmond",
                Region       = "WA",
                PostalCode   = "98052",
                Country      = "USA",
                Phone        = "(425) 555-1234",
                Fax          = string.Empty,
            };

            db.Customers.InsertOnSubmit(newCustomer);
            db.SubmitChanges();

            Assert.AreEqual(db, newCustomer.DataContext);

            db.Contacts.Delete(o => true);
            db.Log = Console.Out;
            if (db.Contacts.Count() == 0)
            {
                var contact = new Contact();
                db.Contacts.InsertOnSubmit(contact);
                db.SubmitChanges();
                Assert.AreEqual(db, contact.DataContext);
            }

            if (db.Contacts.OfType <FullContact>().Count() == 0)
            {
                var contact = new FullContact();
                db.Contacts.InsertOnSubmit(contact);
                db.SubmitChanges();
                Assert.AreEqual(db, contact.DataContext);
                Assert.IsTrue(db.Contacts.OfType <FullContact>().Count() > 0);
            }

            db = new AccessNorthwind("C:/Northwind.mdb");
            var c = db.Contacts.First();

            Assert.AreEqual(db, c.DataContext);

            var f = db.Contacts.OfType <FullContact>().First();

            Assert.AreEqual(db, f.DataContext);
        }
예제 #21
0
 public void GetChangeText()
 {
     var db = new AccessNorthwind("C:/Northwind.mdb");
 }