Search code examples
vb.netlinqc#-4.0entity-framework-4

How to use IsNot in Linq Vb.net


I have a dropdownlist that populates the list of Field1(Id) from Table1(Which has list of Ids) which comes from one entity framework. Table2 also have (Ids) which are from Table 1 that are already used from other entity framework. . So my current dropdownlist should display the ids from both the tables that are not used. My scenario is if one Id is selected and create button is clicked that id should not be seen again in the dropdown list.But i want to filter the values by using the below query but result of below query is not giving any values into the dropdown list. I am very new to VB.Net. Can anyone help me with this.

LINQ Query

Dim weTypeQry1 = (From x In db.Table1 _
                          Where x.field1 Select
                           x IsNot
                          (From y In db1.Table2
                           Where y.feild2 = x.field1
                            Select y)).ToList()

Solution

  • Got the Query for this..Below link helped a lot

    http://stackoverflow.com/questions/877738/linq-excluding-items-from-different-list-types
    
     Dim weTaskTTQry = (From x In db1.Table1 _
                                 Select x.Field1).Distinct.ToList()
    
    Dim weTypeQry1 = db.TAble2.AsEnumerable().Where(Function(p) Not (weTaskTTQry.Contains(p.Filed2))).ToList()