在实体框架中的两个表之间进行选择

发布于 2024-11-19 01:58:22 字数 528 浏览 4 评论 0原文

我想在两个有关系的表之间编写一个选择。 我使用这段代码,但没有得到任何结果。 请告诉我

 using (doctorEntities de = new doctorEntities())
        {
            var select = from tibase in de.Table_infobase_print
                         from tidetail in de.Table_infodetail_print
                         where tibase.ID == tidetail.ID_infobase 
                         select new
                         {
                             tidetail.services_discription,tidetail.price,tibase.folder_code
                         };
        }

I want to write a select between two table that have relation.
I use this code but i get no result.
Please advise me

 using (doctorEntities de = new doctorEntities())
        {
            var select = from tibase in de.Table_infobase_print
                         from tidetail in de.Table_infodetail_print
                         where tibase.ID == tidetail.ID_infobase 
                         select new
                         {
                             tidetail.services_discription,tidetail.price,tibase.folder_code
                         };
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诺曦 2024-11-26 01:58:22

我认为您可能正在寻找联接,无论数据库中是否有匹配的行,您都应该获得结果。目前您还没有对结果做任何事情。

using (doctorEntities de = new doctorEntities())
{
    var results = from tibase in de.Table_infobase_print
                  join tidetail in de.Table_infodetail_print
                  on tibase.ID equals tidetail.ID_infobase 
                  select new
                  {
                      tidetail.services_discription,
                      tidetail.price,
                      tibase.folder_code
                  };
    foreach(var result in results)
    {
        Console.WriteLine("Service description: " + result.services_discription);
    }
}

I think you might be looking for a join instead, regardless you should be getting results if you have matching rows in the database. Also currently you are not doing anything with the results.

using (doctorEntities de = new doctorEntities())
{
    var results = from tibase in de.Table_infobase_print
                  join tidetail in de.Table_infodetail_print
                  on tibase.ID equals tidetail.ID_infobase 
                  select new
                  {
                      tidetail.services_discription,
                      tidetail.price,
                      tibase.folder_code
                  };
    foreach(var result in results)
    {
        Console.WriteLine("Service description: " + result.services_discription);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文