码迷,mamicode.com
首页 > 其他好文 > 详细

linq项目中例子实例

时间:2015-03-31 14:40:26      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

在mvc项目中

var ls = (from i in gt.vendor_login
                  join j in gt.vendor on i.vendor_id equals j.vendor_id
                  into AAA
                  from j in AAA.DefaultIfEmpty()
                  select new myclass { AA = i.vendor_id, BB = j != null ? j.vendor_name_full : null }).ToList();
            ViewBag.abc = ls;
            return View();
然后在视图中

var ls = (from i in gt.vendor_login
                  join j in gt.vendor on i.vendor_id equals j.vendor_id
                  into AAA
                  from j in AAA.DefaultIfEmpty()
                  select new myclass { AA = i.vendor_id, BB = j != null ? j.vendor_name_full : null }).ToList();
            ViewBag.abc = ls;
            return View();

在三层架构中

        public string result()
        {
            return _access.getDataTable("select * from t_parametersrc").Rows.Count.ToString();
        }

        public List<Parametersrc> GetTabel()
        {
            List<Parametersrc> ls = _access.getDataTableForObj<Parametersrc>("select * from t_parametersrc");
            return ls;
        }
        /// <summary>
        /// one
        /// </summary>
        /// <returns></returns>
        public List<Model.Type> GetPayMent()
        {
            var ls = new List<Model.Type>();
            Model.Type pe = new Model.Type();
            List<Parametersrc> lst = GetTabel();
            ls = (from i in lst
                      where i.ParameterType == "payment"
                      select new { code = i.ParameterCode, name = i.parameterName }).ToList().ConvertAll<Model.Type>(w=>new Model.Type{code=w.code,name=w.name});
            return ls;
        }
        /// <summary>
        /// two
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentTwo()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = (from i in lst
                  where i.ParameterType == "payment"
                  //select new { x=i.ParameterCode, y=i.parameterName }).ToList().ConvertAll<Model.Parametersrc>(w => new Model.Parametersrc {ParameterCode=w.x,parameterName=w.y});
                  select new Parametersrc { ParameterCode = i.ParameterCode, parameterName = i.parameterName }).ToList();//㎝硂琌妓
            return ls;
        }
        /// <summary>
        /// three
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentThree()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = (from i in lst
                  where i.ParameterType == "payment"
                  select i).ToList();
            return ls;
        }
        /// <summary>
        /// four
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentFour()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = lst.ToList();
            return ls;
        }
        /// <summary>
        /// five
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentFive()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = lst.Where(p => p.ParameterType.Equals("payment")).Select(p => p).ToList();
            return ls;
        }
     
        /// <summary>
        /// six
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentsix()
        {
            List<Model.Type> ls = new List<Model.Type>();
            var lsls = new List<Parametersrc>();
            List<Parametersrc> lst = GetTabel();
            lsls = lst.Where(p=>p.parameterName.StartsWith("S")).Where(p=>p.ParameterCode.StartsWith("4")).ToList();
            return lsls;
        }
        /// <summary>
        /// seven
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentSeven()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = (from i in lst
                  where i.ParameterType == "payment"
                  select new { x = i.ParameterCode, y = i.parameterName }).ToList().ConvertAll<Model.Parametersrc>(w => new Model.Parametersrc { ParameterCode = w.x, parameterName = w.y });
            return ls;
        }
        /// <summary>
        /// eight
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentEight()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = (from i in lst
                  where i.ParameterType == "payment"
                  select i).ToList();
            return ls;
        }
        /// <summary>
        /// nine
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentNine()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = lst.ToList();
            return ls;
        }
        /// <summary>
        /// ten
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentTen()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = lst.Where(p => p.ParameterType == "payment").ToList();
            return ls;
        }
        /// <summary>
        /// eleven
        /// </summary>
        /// <returns></returns>
        public List<Model.Parametersrc> GetPayMentEleven()
        {
            var ls = new List<Parametersrc>();
            var lst = GetTabel();
            ls = ls.Where(p => p.ParameterType == "payment").ToList();
            return ls;
        }
    }

       public List<Vendor> GetVendorTabel()
        {
            List<Vendor> vdls = _access.getDataTableForObj<Vendor>("select * from vendor");
            return vdls;
        }
        public List<VendorLogin> GetVendorLoginTabel()
        {
            List<VendorLogin> vlls = _access.getDataTableForObj<VendorLogin>("select * from vendor_login");
            return vlls;
        }

        public List<Model.Query.VendorLoginQuery> GetVendorLoginList(string str)
        {
            int i_str = Convert.ToInt32(str);
            var ls = new List<Model.Query.VendorLoginQuery>();
            VendorLoginQuery vdlq = new VendorLoginQuery();
            List<VendorLogin> lsvdlg = GetVendorLoginTabel();
            List<Vendor> lsvd = GetVendorTabel();
            ls = (from i in lsvdlg
                  where i.vendor_id==i_str
                  orderby i.login_id descending
                  from j in lsvd
                  where i.vendor_id==j.vendor_id
                  select new { i, j }).ToList().ConvertAll<VendorLoginQuery>(w => new VendorLoginQuery { login_id = w.i.login_id, vendor_id = w.i.vendor_id, login_ipfrom = w.i.login_ipfrom, login_createdate = w.i.login_createdate, vendor_name_full = w.j.vendor_name_full }).Skip(10).Take(100).ToList();
            return ls;
        }

        public List<Model.Query.VendorLoginQuery> GetVendorLoginListTwo()
        {
            var ls = new List<Model.Query.VendorLoginQuery>();
            List<VendorLogin> lsvdlg = GetVendorLoginTabel();
            List<Vendor> lsvd = GetVendorTabel();
            ls = (from i in lsvdlg
                  join j in lsvd on i.vendor_id equals j.vendor_id
                  into AAA
                  from j in AAA.DefaultIfEmpty()
                  select new VendorLoginQuery {vendor_id = i.vendor_id ,vendor_name_full = j != null ? j.vendor_name_full : null}).ToList();
            return ls;
        }

linq项目中例子实例

标签:

原文地址:http://www.cnblogs.com/sdya/p/4380728.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!