Example #1
0
        private static ObProperty GetProperty <T>(string propertyName)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                return(null);
            }
            var type      = typeof(T);
            var tableName = type.ToTableName();
            var index     = 0;
            var pns       = propertyName.Split('.').ToList();

            while (index < pns.Count)
            {
                propertyName = pns[index];
                var property = type.GetProperties(BindingFlags.Instance | BindingFlags.Public).FirstOrDefault(obj => obj.Name == propertyName);
                if (property == null)
                {
                    return(null);
                }
                if (index + 1 < pns.Count)
                {
                    type = property.PropertyType;
                }
                index++;
            }
            pns.Insert(0, tableName);
            pns.RemoveAt(pns.Count - 1);
            tableName = string.Join("_", pns);
            var obRedefine = ObRedefine.Create(type, tableName);

            return(ObProperty.Create(type, obRedefine, propertyName));
        }
Example #2
0
        public void TestMethod1()
        {
            /*var emp = (EmployeInfo)ObModel.Create(typeof(EmployeInfo));
             * emp.Name = "abc";*/
            /*var cc = new EmployeInfo();
             * cc.Gender = 1;*/
            /*var aa = new Employe().Of();
             * var bb = aa.Department;
             * var cc = new EmployeInfo().Of();
             * cc.Age = 1;
             * cc.Department = new DepartmentInfo().Of();
             * cc.Department.Name = "abc";*/
            //var employe = new Employe("Employes").Of();

            var dal = ObHelper.Create <EmployeInfo>("database=NSmart.Demo01;server=.;uid=sa;pwd=1;Pooling=true;Connection Timeout=300;", "DotNet.Standard.NParsing.SQLServer", ObRedefine.Create <EmployeInfo>("Employes"));

            /*var dal = ObHelper.Create<EmployeInfo, Employe>("database=NSmart.Demo01;server=.;uid=sa;pwd=1;Pooling=true;Connection Timeout=300;", "DotNet.Standard.NParsing.SQLServer");
             * var list = dal.SqlText("SELECT e.ID Id, e.Name Name, e.DepartmentID DepartmentId, d.ID Department_Id, d.Name Department_Name FROM Employes e LEFT JOIN Departments d ON d.ID=e.DepartmentID WHERE e.ID=@ID", new SqlParameter("@ID", 1)).ToList();
             * //var dal = ObHelper.Create<EmployeInfo, Employe>(new Employe().Proxy(), "database=NSmart.Demo01;server=.;uid=sa;pwd=1;Pooling=true;Connection Timeout=300;", "DotNet.Standard.NParsing.SQLServer");
             * /*try
             * {
             *  var emp = new EmployeInfo().Of();
             *  emp.Age = 25;
             *  dal.Update(emp, o => o.Id == 1);
             * }
             * catch (Exception e)
             * {
             *  Console.WriteLine(e);
             *  throw;
             * }*/
            var query = dal
                        .Where(o => o.Department.Id == 1)
                        .GroupBy(o => o.Name)
                        .Join(o => new {
                o,
                o.Department
            }).Select(o => new {
                o.FirstOrDefault().Name,
                Id         = o.Average(a => a.Id),
                Age        = o.Max(a => a.Age),
                Department = new
                {
                    Id   = o.Sum(a => a.Department.Id),
                    Name = o.Count()
                }
            });

            /*.GroupBy(o => new
             * {
             *  o.Gender,
             *  o.Department.Id,
             *  o.Department.Name,
             * })*/
            /*.Select(o => new
             * {
             *  o.Gender,
             *  o.Department.Name,
             *  Department = new
             *  {
             *      o.Department.Name,
             *      o.Department.Id
             *  },
             *  /*Age = o.Avg( k => k.Age).As(k => k.Age),
             *  Name = o.Min(k => k.Id)#1#
             * })
             * .Where(o => o.Age > 20)
             * .OrderByDescending(o => new
             * {
             *  o.Name,
             *  o.Department.Id
             * })
             * .OrderBy(o => o.Department.Name)
             * .Join(o => new
             * {
             *  o.Department,
             *  o.Department.Director
             * })*/;
            //var a = (ObParameterBase) query.ObParameter;
            var list = query.ToList();

            /*var query = dal.GroupBy(o => o.Id).OrderBy(o => o.Id);
             * var list = query.ToList(2, 2, out var count);
             * var a = list;*/
        }