Bob
Bob

Reputation: 79

Entity Framework, ado.net Data Services, odata

I'm very new to Entity Framework, that's my disclaimer! I have a SQL 2008 database with 2 tables, tblModel and tblHairColor. tblModel contains a column named hairID which is a foreign key to the tblHairColor table's primary key of id.

I created the ado.net entity data model and now, following http://msdn.microsoft.com/en-us/library/dd728283.aspx, trying to access my data resources created.

My URL of http://localhost:51157/WcfDataService.svc/tblModels(1)/modelname/$value works great by returning the model's name (of record 1) from the tblModels table. However, when I try to access the hair color via http://localhost:51157/WcfDataService.svc/tblModels(1)/modelname/tblHairColor it does not work, (http 404 not found).

My entity model, generated from my SQL database, created a tblModels navigation property in tblHairColor and a tblHairColor navigation property in tblModel. It also auto generated an association of tblHairColor to tblModel (1 to *). I expected 1 to 1.

My question is what needs to be added/changed to allow this query, http://localhost:51157/WcfDataService.svc/tblModels(1)/modelname/tblHairColor, to return the models hair color?

Thanks in advance for your time. Bob

Upvotes: 2

Views: 328

Answers (1)

Sergey Sirotkin
Sergey Sirotkin

Reputation: 1677

modelname should not be used in URL, just navigational property:

http://localhost:51157/WcfDataService.svc/tblModels(1)/tblHairColor

If you want both model and haircolor, you should use $expand:

http://localhost:51157/WcfDataService.svc/tblModels(1)?$expand=tblHairColor

Upvotes: 1

Related Questions