2017-03-15 188 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控件....用户然后可以将其中的一个拖放到树视图控件,将其添加到PatientRecord Sensitivities列表中。然后,我想让datagridview刷新敏感信息,减去病人记录中已有的敏感信息,这样就不能将相同的敏感信息添加到树视图两次。

希望你能帮上忙。

+0

可能的重复[你会怎么做一个“不在”查询与LINQ?](http://stackoverflow.com/questions/183791/how-would-you-do-a-not-in -query与 - LINQ) – Ben

回答

2

假设PatientSensitivitiesListOfSensitivities实际上是一个List而不是一些自定义类型,我觉得一个Except()会做你要找的东西。

this.dgvSearchResults.DataSource = ListOfSensitivities.Except(PatientSensitivities).ToArray(); 
相关问题