表连接或Linq / Lambda表达式比较 [英] Table Joins or Linq/Lambda expression comparison

查看:90
本文介绍了表连接或Linq / Lambda表达式比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的SQL Server数据库中有六个表。



步骤1:我将表1,表2和表3联合到Datatable1中。



步骤2:我将表4,表5和表6全部联合到Datatable2中。



在所有6个表中常见的列是AlbumID,PictureID,StoryID。



现在我想比较两个Datatables中的这些列,并在Datatable1中放置一个标志(True)所在的数据两个数据表都匹配其他False。



我正在考虑使用Linq或Lambda Expression进行比较。这是正确/最好的方法吗?或者我应该去TABLE JOINS吗?



基本上桌子应该有4列: -



AlbumID ,PictureID,StoryID,Flag

仅当Datatable2中存在AlbumID或PictureID或StoryID时,标志才为真

I have six tables in my SQL Server database.

Step 1: I UNION ALL Table 1, Table 2 and Table 3 into Datatable1.

Step 2: I UNION ALL Table 4, Table 5 and Table 6 into Datatable2.

In all the 6 tables the common columns are AlbumID,PictureID,StoryID.

Now I want to compare these columns in both the Datatables and put a flag (True) in Datatable1 where the data in both the datatables match else False.

I am thinking to use Linq or Lambda Expression to do the comparison. Is this the correct/best way to do this? OR should I go for TABLE JOINS?

Basically the table should have 4 columns :-

AlbumID, PictureID, StoryID, Flag
Flag would be true only if AlbumID or PictureID or StoryID is present in Datatable2

推荐答案

我想它'这是一个意见问题,但我个人会加入表格或使用 EXISTS [< a href =http://msdn.microsoft.com/en-us/library/ms188336.aspxtarget =_ blanktitle =New Window> ^ ]子句。



但是,我要做的第一件事就是停止思考数据库设计本身。如果你的表有这么多常见的列,那么就会提出一个问题,即数据库是否正常规范化了。



因此,如果不了解更多有关表的话,我会建议你仔细看看数据库设计,并考虑是否有6个表都有列AlbumID,PictureID,StoryID,你可以简化设计。
I guess it''s a matter of opinion, but personally I would either join the tables or use an EXISTS[^] clause.

However, the first thing I would do is to stop to think the database design itself. If you have tables that have so many common columns, it raises the question if the database s normalized properly.

So without knowing anything more about the tables, I would advice you to have a closer look at the database design and consider if instead of having 6 tables which all have columns AlbumID,PictureID,StoryID could you simplify the design.


这篇关于表连接或Linq / Lambda表达式比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆