千家信息网

Linq Setting字段怎么用

发表于:2024-11-14 作者:千家信息网编辑
千家信息网最后更新 2024年11月14日,这篇文章将为大家详细讲解有关Linq Setting字段怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Linq Setting字段存储本文介绍Linq Set
千家信息网最后更新 2024年11月14日Linq Setting字段怎么用

这篇文章将为大家详细讲解有关Linq Setting字段怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

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(递归查询,查询父节点下所有节点)

  1. var query = (from item1 in dc.SysOrganization

  2. where (item1.FatherSysOrganizationID == orgId) && item1.IsDel == false

  3. select new SysOrganizationInfo { SysOrganizationID =item1.SysOrganizationID,
    Name=item1.Name,Code=item1.Code,BaseProvinceID=(int)item1.BaseProvinceID,
    BaseCityID=(int)item1.BaseCityID})

  4. .Union(

  5. from item2 in dc.SysOrganization

  6. join item3 in dc.SysOrganization

  7. on item2.FatherSysOrganizationID equals item3.SysOrganizationID

  8. where (item2.SysOrganizationID == orgId) && item2.IsDel == false

  9. select new SysOrganizationInfo { SysOrganizationID = item2.SysOrganizationID,
    Name = item2.Name, Code = item2.Code, BaseProvinceID = (int)item2.BaseProvinceID,
    BaseCityID = (int)item2.BaseCityID });

Linq中Join连所子查询结合

  1. var roles = from aa in(

  2. from a in dc.SysOrganizationRoleUser

  3. join b in dc.SysOrganizationRole on a.SysRoleID equals b.SysRoleID

  4. join c in dc.SysOrganizationRoleFunctionItem on b.SysRoleID equals c.SysRoleID

  5. join d in dc.SysFunctionItem on c.SysFunctionItemID equals d.SysFunctionItemID

  6. join d2 in dc.SysFunctionItem on c.SysFunctionItemID equals d2.SysFunctionItemID

  7. where a.SysUserID == userID

  8. select d)

  9. from bb in dc.SysFunctionItem

  10. where aa.SysFunctionItemID == bb.SysFunctionItemID ||
    aa.FatherFunctionItemID == bb.SysFunctionItemID

  11. select bb;

Linq中的左连接查询用到 DefaultIfEmpty() 语法

  1. var svcUser = from a in hdc.SysServiceCenterUser

  2. join b in hdc.SysServiceCenter on a.SysServiceCenterID equals b.SysServiceCenterID

  3. join c in hdc.SysServicePositionUser on a.SysUserID equals c.SysUserID into pous

  4. from c in pous.DefaultIfEmpty()

  5. join d in hdc.SysServiceCenterPosition on c.SysServicePositionID
    equals d.SysServicePositionID into po

  6. from d in po.DefaultIfEmpty()

  7. where (_SysServiceCenterID == 0 ? true : a.SysServiceCenterID == _SysServiceCenterID)

  8. && (_SysServicePositionID == 0 ? true : (from w in hdc.SysServicePositionUser where
    w.SysServicePositionID == _SysServicePositionID select w.SysUserID).Contains(a.SysUserID))

  9. && (_Name == null || _Name.Trim() == "" ? true : a.FullName.Contains(_Name))

  10. && (_Code == null || _Code.Trim() == "" ? true : a.Code == _Code)

  11. select new Svc

  12. {

  13. _SysUserID = (a.SysUserID == null ? 0 : a.SysUserID),

  14. _SysServiceCenterID = (a.SysServiceCenterID==null?0:(int)a.SysServiceCenterID),

  15. //_SysServicePositionID = (int)c.SysServicePositionID,

  16. _SvcName = b.Name,

  17. //_PositionName = d.Name,

  18. _LoginName = a.LoginName,

  19. _FullName = a.FullName,

  20. _Code = (a.Code==null?"":a.Code)

  21. };

关于"Linq Setting字段怎么用"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

0