I have a very big problem solving this issue I have 2 tables
first table is : http://lh3.ggpht.com/_uMvfbnPHuko/SYPJQ1ZsBDI/AAAAAAAAAKs/eq49xquy3jM/s800/Untitled-2.jpg
which contains a modules (id and name)
second table is http://lh6.ggpht.com/_uMvfbnPHuko/SYPJQ4IXGwI/AAAAAAAAAK0/zmTIO6V-UEQ/s800/Untitled-3.jpg
which contains users ids and their preferred modules’ numbers
now lets move to the problem I want to generate a list of checkboxes
for example for the userid 1 which has the following modules ‘3,2 and 4’ the result will be
http://lh4.ggpht.com/_uMvfbnPHuko/SYPJQ_LJeVI/AAAAAAAAAK8/6RV8a1S8eCY/s800/Untitled-4.jpg
notice that ‘recommended for you’ checkbox is not checked because the user 1 does not have module id ‘1’
I spent a long time trying to solve this problem using c# and LINQ
see the result of my effort 🙂 (the following code does not work)
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 };
If LINQ is easy for you please try to solve this one? any questions?
Your query doesn’t works because LinqToSQL tries to translate everything to plain SQL.
If you cannot refactor your schema, and use an intermediate table since you clearly have a many-to-many relation ship, you can do something like this: