您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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(遞歸查詢,查詢父節點下所有節點)
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字段怎么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。