Example #1
0
        public void DynamicProperty2()
        {
            var mappingSource = new FluentMappingSource(delegate
            {
                var contextMapping      = new DataContextMapping <DataContext>();
                contextMapping.Provider = new ProviderAttribute(typeof(ALinq.MySQL.MySqlProvider));

                var employeeMapping = new EntityMapping <MyEmployee>();
                employeeMapping.Table("Employees")
                .Column(o => o["EmployeeID"], o => o.PrimaryKey().AutoSyncOnInsert())
                .Column(o => o["City"])
                .Column(o => o["FirstName"])
                .Column(o => o["LastName"]);

                contextMapping.Add(employeeMapping);
                return(contextMapping);
            });

            var conn = "server=localhost;User Id=root;Password=test;Persist Security Info=True;database=northwind";
            var db   = new DataContext(conn, mappingSource)
            {
                Log = Console.Out
            };

            var table = db.GetTable <MyEmployee>();

            table.Select(o => o["FirstName"]).Cast <dynamic>().ToArray();
            table.Select("['FirstName']").Cast <dynamic>().ToArray();

            table.Select(o => new { OrderDate = o["FirstName"] }).ToArray();
            table.Select("new (['FirstName'] as F, ['LastName'] as L)").Cast <dynamic>().ToList()
            .ForEach(o => Console.WriteLine(o.F + " " + o.L));
        }
Example #2
0
        public void DynamicColumGroup()
        {
            var mappingSource = new FluentMappingSource(delegate
            {
                var contextMapping      = new DataContextMapping <DataContext>();
                contextMapping.Provider = new ProviderAttribute(typeof(ALinq.MySQL.MySqlProvider));

                var employeeMapping = new EntityMapping <MyEmployee>();
                employeeMapping.Table("Employees")
                .Column(o => o["EmployeeID"], o => o.PrimaryKey().AutoSyncOnInsert())
                .Column(o => o["City"])
                .Column(o => o["FirstName"])
                .Column(o => o["LastName"]);

                contextMapping.Add(employeeMapping);
                return(contextMapping);
            });

            var conn  = "server=localhost;User Id=root;Password=test;Persist Security Info=True;database=northwind";
            var db    = new DataContext(conn, mappingSource);
            var table = db.GetTable <MyEmployee>();

            var keys1 = table.GroupBy(o => o["City"])
                        .Select(o => o.Key);

            keys1.ToList().ForEach(Console.WriteLine);

            var keys2 = table.GroupBy(o => new { F = o["FirstName"], L = o["LastName"] })
                        .Select(o => o.Key);

            keys2.ToList().ForEach(Console.WriteLine);
        }
Example #3
0
        public void Test3()
        {
            var mappingSource = new FluentMappingSource(delegate
            {
                var contextMapping      = new DataContextMapping <DataContext>();
                contextMapping.Provider = new ProviderAttribute((typeof(AccessDbProvider)));

                var employeeMapping = new EntityMapping <MyEmployee>();
                employeeMapping.Table("Employees")
                .Column(o => (string)o["City"])
                .Column(o => (string)o["FirstName"])
                .Column(o => (string)o["LastName"]);

                contextMapping.Add(employeeMapping);
                return(contextMapping);
            });
            var dc        = new DataContext("C:/Northwind.mdb", mappingSource);
            var metaTable = dc.Mapping.GetTable(typeof(MyEmployee));

            Assert.IsNotNull(metaTable);
        }