There are two tables: rule and rulegroup. rulegroup is the Association table between the rule table and the group table (rule, multi-to-many relationship with the group, rulegroup to rule should be N: 1 (Multiple-to-one), and vice versa. Now we do the innerjion operation on the two tables. Subsonic can be written in the following two ways.
Note: to ensure that the correct SQL statement is generated, place two tables in subsoinc, that is, from <XXX>. innerjoin (yyy, XXX )...
XXX, YYY indicates rulegroup, or rule table. If it is not cross-placed, an SQL statement such as XXX innerjoin XXX on xxx. nn = yy. NN is generated.
CodeAs follows:
Sqlquery q = new select ("name", "ruleid"). From <Rulegroup> (). Innerjoin (kwstool. Dal.Rule. Idcolumn,Rulegroup. Ruleidcolumn). Where ("groupid"). isrelative to (1 );
Response. Write (Q. tostring () + "<br> ");
Q = new select ("name", "ruleid"). From <kwstool. Dal.Rule> (). Innerjoin (Rulegroup. Ruleidcolumn, kwstool. Dal.Rule. Idcolumn). Where ("groupid"). isrelative to (1 );
Response. Write (Q. tostring ());
Output result:
1: Select name, [DBO]. [rulegroup]. [ruleid] from [DBO]. [rulegroup] inner join [DBO]. [rule] on [DBO]. [rulegroup]. [ruleid] = [DBO]. [rule]. [ID] Where [DBO]. [rulegroup]. [groupid] = @ groupid0
2: select [DBO]. [rule]. [name], ruleid from [DBO]. [rule] inner join [DBO]. [rulegroup] on [DBO]. [rule]. [ID] = [DBO]. [rulegroup]. [ruleid] Where groupid = @ groupid0
In addition.. the dbml file converts a one-to-multiple relationship in the database (such as rule to rulegroup) into an aggregate relationship in the "class chart", which is represented as: Rule <> -------------> rulegroup, that is, a rule contains multiple rulegroups. Note that the direction of the arrow is exactly the opposite to that of the database erdiagram (database model diagram.