I have a big problem solving this problem. I have 2 tables
The first table is
There is a module (ID and name)
another table
containing the user ID and their favorite modules' number
< P> Now, for example, I want to generate a list of checkboxes for IIDFor example, in which the following module will be "3,2 and 4" result
Note that the "Recommended for you" checkbox is not checked because the module id "1" is not in user 1
I have a long time to solve this problem using C # and LINQ
See the result of my efforts :) (The following code does not work)
If LINQ is easy for you, please try to solve it? Any questions?
Your query does not work because LinqToSQL tries to translate everything into plain SQL
If you can not apply your schema again, and use an intermediate table because you have obviously many-to-many relationship ships, then you can do something like this. Are:
var userModules = Db.userModules.SingleOrDefault (m => m.userId == myUserId). Module; // Get the user's modules (a comma-delimited string) var integerModules = modules.Split (','). Select (m = & gt; int.Parse (m)); // IEnumerable & lt; Int & gt; Change the comma-delimited string for Var query = db.modules.Select (x = & gt; new {x.moduleId, x.moduleName, isChecked = integerModules.Contains (x.moduleId)}); // and finally query
Comments
Post a Comment