实体框架、ado.net 数据服务、odata
我对实体框架非常陌生,这是我的免责声明!我有一个 SQL 2008 数据库,有 2 个表:tblModel 和 tblHairColor。 tblModel 包含一个名为hairID 的列,它是tblHairColor 表的主键id 的外键。
我创建了 ado.net 实体数据模型,现在遵循 http://msdn。 microsoft.com/en-us/library/dd728283.aspx,尝试访问我创建的数据资源。
我的 URL http://localhost:51157/WcfDataService.svc/tblModels(1) /modelname/$value 通过从 tblModels 表返回模型的名称(记录 1)非常有效。但是,当我尝试通过 http://localhost:51157 访问头发颜色时/WcfDataService.svc/tblModels(1)/modelname/tblHairColor 它不起作用,(未找到http 404)。
我的实体模型是从 SQL 数据库生成的,在 tblHairColor 中创建了 tblModels 导航属性,并在 tblModel 中创建了 tblHairColor 导航属性。它还自动生成 tblHairColor 与 tblModel 的关联(1 到 *)。我期望 1 比 1。
我的问题是需要添加/更改什么才能允许此查询, http://localhost:51157/WcfDataService.svc/tblModels(1)/modelname/tblHairColor,返回模型头发颜色?
预先感谢您的宝贵时间。 鲍勃
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型名称不应在 URL 中使用,而应在导航属性中使用:
如果您想要两者模型和头发颜色,则应使用 $expand:
modelname should not be used in URL, just navigational property:
If you want both model and haircolor, you should use $expand: