Linq有很多值得学习的地方,这里我们主要介绍Linq Setting字段,包括介绍Linq中Join连所子查询结合等方面。
“专业、务实、高效、创新、把客户的事当成自己的事”是我们每一个人一直以来坚持追求的企业文化。 成都创新互联公司是您可以信赖的网站建设服务商、专业的互联网服务提供商! 专注于成都网站设计、成都网站建设、软件开发、设计服务业务。我们始终坚持以客户需求为导向,结合用户体验与视觉传达,提供有针对性的项目解决方案,提供专业性的建议,创新互联建站将不断地超越自我,追逐市场,引领市场!
Linq Setting字段存储
本文介绍Linq Setting字段,这个用过Linq的人都知道它的好处,如在设计一张表如学生信息表,如学习爱好,性格,生活经历等这些字段,相信大家在以前的设计理念是将三个字段设计成三个 Nvarchar(8000)类型字段,或者有些设计成 Text 类型字段,这些设计都没错,但都不是很好。
现在有 Linq,可以将这三个字段都放在Linq Setting字段中(注意这里,字段的名称必须为Setting),Linq Setting字段设置成 image 类型即可实现数据的存储。如何用C#语法来存储呢?????以后有空再说。用Setting字段存储的数据,缺点是做条件查询时,用Setting作为查询条件就有些复杂了,一般不作条件查询。
- private string _hotelDescription = string.Empty;//兴趣
- public string HotelDescription { get { return _hotelDescription;
- }
- set { _hotelDescription = value; } }
- partial void OnLoaded()
- {
- byte[] bytes = Setting.ToArray();
- CSetting setting = new CSetting(bytes);
- load(setting);
- }
- partial void OnValidate(System.Data.Linq.ChangeAction action)
- {
- CSetting setting = new CSetting();
- save(setting);
- byte[] bytes = setting.ToByteArray();
- Setting = new Binary(bytes);
- }
- private void save(CSetting setting)
- {
- setting.Set("desc", _hotelDescription);
- }
- private void load(CSetting setting)
- {
- _hotelDescription = setting.Get("desc", string.Empty);
- }
Linq中的Union(递归查询,查询父节点下所有节点)
- var query = (from item1 in dc.SysOrganization
- where (item1.FatherSysOrganizationID == orgId) && item1.IsDel == false
- select new SysOrganizationInfo { SysOrganizationID =item1.SysOrganizationID,
Name=item1.Name,Code=item1.Code,BaseProvinceID=(int)item1.BaseProvinceID,
BaseCityID=(int)item1.BaseCityID})- .Union(
- from item2 in dc.SysOrganization
- join item3 in dc.SysOrganization
- on item2.FatherSysOrganizationID equals item3.SysOrganizationID
- where (item2.SysOrganizationID == orgId) && item2.IsDel == false
- select new SysOrganizationInfo { SysOrganizationID = item2.SysOrganizationID,
Name = item2.Name, Code = item2.Code, BaseProvinceID = (int)item2.BaseProvinceID,
BaseCityID = (int)item2.BaseCityID });
Linq中Join连所子查询结合
- var roles = from aa in(
- from a in dc.SysOrganizationRoleUser
- join b in dc.SysOrganizationRole on a.SysRoleID equals b.SysRoleID
- join c in dc.SysOrganizationRoleFunctionItem on b.SysRoleID equals c.SysRoleID
- join d in dc.SysFunctionItem on c.SysFunctionItemID equals d.SysFunctionItemID
- join d2 in dc.SysFunctionItem on c.SysFunctionItemID equals d2.SysFunctionItemID
- where a.SysUserID == userID
- select d)
- from bb in dc.SysFunctionItem
- where aa.SysFunctionItemID == bb.SysFunctionItemID ||
aa.FatherFunctionItemID == bb.SysFunctionItemID- select bb;
Linq中的左连接查询用到 DefaultIfEmpty() 语法
- var svcUser = from a in hdc.SysServiceCenterUser
- join b in hdc.SysServiceCenter on a.SysServiceCenterID equals b.SysServiceCenterID
- join c in hdc.SysServicePositionUser on a.SysUserID equals c.SysUserID into pous
- from c in pous.DefaultIfEmpty()
- join d in hdc.SysServiceCenterPosition on c.SysServicePositionID
equals d.SysServicePositionID into po- from d in po.DefaultIfEmpty()
- where (_SysServiceCenterID == 0 ? true : a.SysServiceCenterID == _SysServiceCenterID)
- && (_SysServicePositionID == 0 ? true : (from w in hdc.SysServicePositionUser where
w.SysServicePositionID == _SysServicePositionID select w.SysUserID).Contains(a.SysUserID))- && (_Name == null || _Name.Trim() == "" ? true : a.FullName.Contains(_Name))
- && (_Code == null || _Code.Trim() == "" ? true : a.Code == _Code)
- select new Svc
- {
- _SysUserID = (a.SysUserID == null ? 0 : a.SysUserID),
- _SysServiceCenterID = (a.SysServiceCenterID==null?0:(int)a.SysServiceCenterID),
- //_SysServicePositionID = (int)c.SysServicePositionID,
- _SvcName = b.Name,
- //_PositionName = d.Name,
- _LoginName = a.LoginName,
- _FullName = a.FullName,
- _Code = (a.Code==null?"":a.Code)
- };
文章题目:LinqSetting字段描述
网页路径:http://www.shufengxianlan.com/qtweb/news4/547804.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联