2009-04-22 9 views
1

Dies könnte ein Entity Framework bezogene Frage, jedenfalls sein, hier geht:ADO.NET Data Services: Wie filtern Sie eine Entität basierend auf Fremdschlüsseln?

das folgende einfache Datenbank-Schema vor:

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) 
) 

Was ich will, ist es, Produkte auf einem Lieferanten filtern und eine Kategorie. Normalerweise würde ich nur eine Kategorie-ID und eine Lieferanten-ID liefern, aber da ich meine Datenbank durch EF bin aussetzt, Data Service erlaubt mich nicht, so etwas zu tun:

$filter=SupplierId eq 1 and CategoryId eq 2 

Dies scheint ein ziemlich häufiges Szenario, also muss es möglich sein. Aber wie?

Antwort

2

Es stellt sich heraus, es ist ziemlich einfach, hier ist, wie es gemacht wird:

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

Grüße.