本文介绍了使用关联查询具有三个链接表的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,其中有几个表使用关联链接。是否可以查询数据库以使用关联从表中提取记录?看下面的代码?



我试图从所有三个表中获取值,即从表BOOK提取P_C和STRIKE,从表OPTIONS提取OPT_MULTIPLIER和OPT_EXPIRY,最后从表SKEW提取SKEW_A 。



我可以获得一层下来的记录,但我不知道如何从两个表格中获取记录。这里http://imgur.com/D7kh1oE是映射图像的链接。



我尝试过:



I have a database with several tables linked using associations. Is it possible to query the database to extract records from tables two tiers down using the association? See code below?

I am trying to get values from all three tables i.e from table BOOK extract P_C and STRIKE, from table OPTIONS extract OPT_MULTIPLIER and OPT_EXPIRY, and finally from table SKEW extract SKEW_A.

I can get records one tier down, but I don't know how to get records from a table two tiers down. Here "http://imgur.com/D7kh1oE" is a link to the mapping image.

What I have tried:

using (lnkTRADERDataContext DATActx = new lnkTRADERDataContext())
{

    var qryBOOK = from B in DATActx.BOOKs where B.DEAL == 1
                  select new clsTRADER()
                  {
                      P_C = B.P_C,       //main table
                      STRIKE = B.STRIKE, //main table
                      OPT_EXP = B.OPTIONs.Single(X => X.OPT_EXPIRY),        //one tier down
                      OPT_MULT = B.OPTIONs.Single(X => X.OPT_MULTIPLIER),   //one tier down
                      SKEW_A = B.OPTIONs.SKEWs.Single(X => X.SKEW_A)        // two tiers down
               };
}

推荐答案


这篇关于使用关联查询具有三个链接表的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:04