Inner Join Operation in subsonic

Source: Internet
Author: User

 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.