2017-03-15 5 views
0

LINQクエリで助けが必要です。ここでLINQクエリ - あるリストの値を別のリストから除外します

は私のコードです:

private void ReturnSensitivitiesSearchResults() 
{ 

    PatientRecord PMR = new PatientRecord();   

    // Return the list of sensitivities (Ingredient objects), but do not include any where the "SuitableForSensitivityChecking" is false - as we wouldn't want to include ingredients in the list where 
    // they can't be screened for sensitivities. - This returns an array of Ingredient[] 
    var ListOfSensitivities = FDBSystem.Navigation.GetIngredientsByName(txtSearchText.Text + "*", sensitivityType).Where(n => n.SuitableForSensitivityChecking != false); 

    // Return a list of all of the Sensitivities logged on a PatientRecord (which is a list of Ingredient objects) 
    var PatientSensitivities = PMR.Sensitivities; 

    // Populate the drug information into the grid control. 

    this.dgvSearchResults.DataSource = ListOfSensitivities.ToArray(); 
} 


class PatientRecord 
{ 
    public List<Ingredient> Sensitivities = new List<Ingredient>(); 
} 

私は必要なものの感度のリストを返すLINQ文ですが、PatientRecordセンシティビティリストにあるものを含めていません。

DataGridviewコントロール内のすべての感度をリストしています....ユーザは、これらのうちの1つをツリービューコントロールにドラッグアンドドロップして、PatientRecord Sensitivitiesリストに追加することができます。私はdatagridviewを、患者の記録に既に存在する感受性を差し引いた感度で更新したいので、同じ感度をtreeviewに2回追加することはできません。

希望すると助かります。 PatientSensitivitiesListOfSensitivitiesを想定すると、

+0

可能性のある重複した[あなたはLINQクエリで「ないで」だろうどのように?](http://stackoverflow.com/questions/183791/how-would-you-do-a-not-in -query-with-linq) – Ben

答えて

2

が実際にListではなく、いくつかのカスタムタイプです、私はExcept()は、あなたが探しているものをやると思います。

this.dgvSearchResults.DataSource = ListOfSensitivities.Except(PatientSensitivities).ToArray(); 
関連する問題