views:

262

answers:

1

Hi

This might be a entity framework related question, anyway, here goes:

Consider the following simple database schema:

CREATE TABLE Supplier(
    SupplierId int identity(1,1) not null primary key,
    DisplayName nvarchar(50)
)

CREATE TABLE Category(
    CategoryId int identity(1,1) not null primary key,
    DisplayName nvarchar(50)
)

CREATE TABLE Product(
    ProductId int identity(1,1) not null primary key,
    SupplierId int references Supplier.SupplierId,
    CategoryId int references Category.CategoryId,
    DisplayName nvarchar(50)
)

What I want is to filter products based on a supplier and a category. Normally I would just supply a category id and a supplier id, but since I am exposing my database through EF, Data Services do not allow me to do something like this:

$filter=SupplierId eq 1 and CategoryId eq 2

This seems like a pretty common scenario, so it must be possible. But how?

Best regards, Egil.

+2  A: 

It turns out it is pretty easy, here is how it is done:

$filter=Product/Supplier/SupplierID eq 1 and Products/Category/CategoryID eq 1

Regards.

Egil Hansen