and i have added two differenct linq to sql classes for above. and now i want to use join on the moduleid so that when i make method it returns list with the all the columns of userpermission with modulename of module table. currently i have written
following code without join.
public List<BWS.DB.DAL.UserPermission> GetUserPermissionList(Int32 CompanyID, Int32 UserTypeID)
{
UserPermissionsDataDataContext objDataContext = new UserPermissionsDataDataContext();
return objDataContext.UserPermissions.Where(UP => UP.CompanyId == CompanyID && UP.UserTypeID == UserTypeID).ToList();
}
public Int32 Update(List<BWS.DB.DAL.UserPermission> PermissionList)
{
try
{
UserPermissionsDataDataContext objDataContext = new UserPermissionsDataDataContext();
for (int i = 0; i < PermissionList.Count; i++)
{
UserPermission temp =(objDataContext.UserPermissions.First(PL => PL.id == PermissionList[i].id));
PropertyInfo[] properties = temp.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
if (null != property.GetSetMethod())
{
MappingProvider.MapProperties(PermissionList[i], temp, property);
}
}
objDataContext.SubmitChanges();
}
return 1;
}
catch
{
return -1;
}
}
Please suggest some easy way so that the update operation is also simple. Thanks
mehtapratik
Member
269 Points
305 Posts
how to use join with linq?
Mar 03, 2009 11:57 AM | LINK
hi everyone, I am new to linq and i have some difficulty with join.
I have two tables:
1) UserPermission - (columns: permissionid, fkmoduleid, permissionname)
2) module (columns: pkmoduleid, modulename)
and i have added two differenct linq to sql classes for above. and now i want to use join on the moduleid so that when i make method it returns list with the all the columns of userpermission with modulename of module table. currently i have written following code without join.
public List<BWS.DB.DAL.UserPermission> GetUserPermissionList(Int32 CompanyID, Int32 UserTypeID)
{
UserPermissionsDataDataContext objDataContext = new UserPermissionsDataDataContext();
return objDataContext.UserPermissions.Where(UP => UP.CompanyId == CompanyID && UP.UserTypeID == UserTypeID).ToList();
}
public Int32 Update(List<BWS.DB.DAL.UserPermission> PermissionList)
{
try
{
UserPermissionsDataDataContext objDataContext = new UserPermissionsDataDataContext();
for (int i = 0; i < PermissionList.Count; i++)
{
UserPermission temp =(objDataContext.UserPermissions.First(PL => PL.id == PermissionList[i].id));
PropertyInfo[] properties = temp.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
if (null != property.GetSetMethod())
{
MappingProvider.MapProperties(PermissionList[i], temp, property);
}
}
objDataContext.SubmitChanges();
}
return 1;
}
catch
{
return -1;
}
}
Please suggest some easy way so that the update operation is also simple. Thanks
Espirit Softwares Pvt. Ltd.
India.
HarshBardhan
Star
10118 Points
1749 Posts
Re: how to use join with linq?
Mar 03, 2009 12:05 PM | LINK
Hi,
Check these links.
http://code.msdn.microsoft.com/LinqtoSQLJoinExample
http://code.msdn.microsoft.com/LinqtoSQLJoinExample/Release/ProjectReleases.aspx?ReleaseId=58
Harsh Bardhan
Hemant@Silve...
Member
108 Points
19 Posts
Re: Re: how to use join with linq?
Mar 05, 2009 04:24 AM | LINK
Define the association(PK-Fk relation ) between tables in database or set associationmapping in datamodel design.
once proper association is created you will get module table as an property of userpermission entitiy. No need to loop in to get master table.
you can access as
from userPerm in userPermission
select userPerm.Module.moduleName
Hemant Patidar
Diaspark Inc., Indore