大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章将为大家详细讲解有关Linq Setting字段怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
创新互联是一家专业提供孟村企业网站建设,专注与成都做网站、成都网站设计、HTML5、小程序制作等业务。10年已为孟村众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
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.SysFunctionItemIDselect 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 pofrom 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)
};
关于“Linq Setting字段怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。