Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var q = from m in db.modules
- from um in db.usersModules.Where(um2 => um2.userId == myUserId).Single().modules.Trim().Split(',')
- where um.Contains(m.moduleId.ToString())
- select new
- {
- moduleid = here i want the module id from modules table
- modulename = here i want the modulename from modules table
- ischecked = here i want "true" or "false" depending on if the user has this module or not
- };
- var userModules = db.userModules.SingleOrDefault(m => m.userId == myUserId).modules;
- // Get the modules of the user (a comma delimited string)
- var integerModules = modules.Split(',').Select(m => int.Parse(m));
- // Convert the comma delimited string to IEnumerable<int>
- var query = db.modules.Select(x => new {
- x.moduleId,
- x.moduleName,
- isChecked = integerModules.Contains(x.moduleId)
- }); // And finally do the query
- Table: "modules"
- moduleId moduleName
- 1 Recommended...
- 2 Blah
- 3 ...
- Table: "usersModule"
- userId moduleId
- 1 3
- 1 2
- 1 4
- var q =
- from m in db.modules
- select new {
- m.moduleId,
- m.name,
- db.usersModules.Exists(um => um.userId == myUserId)
- };
Add Comment
Please, Sign In to add comment