0

This is the SQL query I have written:

select * from Addresses a 
join ProviderAddresses pa on a.address_k =  pa.address_k
where pa.provider_k = 'ABC123'
and pa.active = 1
and a.active = 1
and pa.addresstype_rtk = 'HOME'

And this is the LINQ query I wrote for it:

public IQueryable<Addresses> GetAddressesesForProvider(string provider_k, string addresstype_rtk)
{
    var query = from a in this.Context.Addresses
        join pa in this.Context.ProviderAddresses on a.Address_K equals pa.Address_K
        where pa.AddressType_RTK == addresstype_rtk
                                   && pa.Active == true
                                   && a.Active == true
        select a;

    return query;
}

But it is wrong. The LINQ one return thousands of records and the SQL one returns only one record.

It is IQueryable because later I need to go through its results with a for-each loop. In the SQL I am passing hard coded values for testing but in my code for me LINQ method I also pass the same hard coded values so that is not the issue.

1

1 Answer 1

1

Looks like you may have just missed adding the provider_k condition to the where;

public IQueryable<Addresses> GetAddressesesForProvider(string provider_k, string addresstype_rtk)
{
    var query = from a in this.Context.Addresses
        join pa in this.Context.ProviderAddresses on a.Address_K equals pa.Address_K
        where pa.Provider_K == provider_k &&
              pa.AddressType_RTK == addresstype_rtk &&
              pa.Active == true &&
              a.Active == true
        select a;

    return query;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.