header image

Entity Note

CLEAR TABLE:
pthg_sysEntities db = new pthg_sysEntities();
db.Database.ExecuteSqlCommand(“TRUNCATE TABLE [SwagLog]”);
db.SaveChanges();
=====================================================
INNER JOIN TWO TABLES TOGETHER WITH CONDITIONS:
var FunctionState = from f in db.UTFunction
join rd in db.UTRoleDetail.Where(u => u.RoleID == RoleID)
on f.ID equals rd.FunctionID into subGrp

from sub in subGrp.DefaultIfEmpty()
where f.CategoryID == CategoryID
//from subN in subGrp
select new
{
Name = f.Name,
isActivate = sub.RoleID == null ? false : true
};
=====================================================
DEAL WITH NULL VARIABLE:
from c in db.UTCategory
join d in db.UTUserDetail.Where(d => d.UserID == intUserID)
on new { ID = c.ID } equals new { ID = d.CategoryID }
into subSet
from sub in subSet.DefaultIfEmpty()

select new
{
cateID = c.ID,
cateName = c.Name,
userID = (int?)sub.UserID,
roleID = (int?)sub.RoleID,
roleName = (string)
};