2014-01-09 83 views
1

我有兩個不同的數據庫,它們在某些列中具有相同的屬性。 我的存儲庫的目標是獲取這些屬性並進行比較。在ADO.NET中比較來自不同數據庫的兩個數據讀取器

所以,我就是這麼做的:

public sealed class Product 
{ 
    public string BarCode{ get; set; } 
    public string CreationDate{ get; set; } 
    public string Modifier{ get; set; } 
    public string Status { get; set; } 
} 

public IEnumerable<Product> GetProductsDB1() 
{ 
    // ADO.NET stuff using DataReader returning a Product List from DB1 
} 

public IEnumerable<Product> GetProductsDB2() 
{ 
    // ADO.NET stuff using DataReader returning a Product List from DB2 
} 

public IEnumerable<Product> Compare() 
{ 
    var db2 = GetProductsDB2() 
    var db1 = GetProductsDB1() 
    //Comparing both lists here and returning the result list to display in GridView 
} 

林不知道,如果是做的最好的辦法。我希望有任何建議可以使用正確的概念來做到這一點。因爲這種比較是痛苦的,我有超過30個對象來做同樣的事情。

謝謝。

回答

0

您是否期望兩個列表中都存在相同的產品?如果是這樣,是否有每個產品獨有的標識符?

如果有一個唯一標識符可用,那麼您正在尋找在兩個列表(本例中包含全部外連接,包含每個列表中的所有記錄)之間進行連接。

編輯: 假設我們使用的是產品的性能「密碼條」,你可以使用如下代碼下面來比較的東西:


    var tJoined = db1.Join(db2, 
    list1Product => list1Product.CodeBar, 
    list2Product => list2Product.CodeBar, 
    (list1Product, list2Product) => new { Product1 = list1Product, Product2 = list2Product } 
); 

    foreach(var tProductComparision in tJoined) { 
    if(tProductComparison.Product1.PropertyOfInterest != tProductComparison.Product2.PropertyOfInterest) { 
     //do something here 
    } 
    } 
+0

世界上沒有唯一標識符。是的,這些產品存在於同一個列表中。 – gog

+0

你希望做什麼比較呢? – Matt

+0

在流程工作流程中,產品在這兩個第三部分數據庫中同時添加,但有時數據已損壞且值不相同。所以我需要檢查它並顯示。 – gog

相關問題