实体框架、ado.net 数据服务、odata

发布于 2025-01-07 11:05:25 字数 1154 浏览 7 评论 0原文

我对实体框架非常陌生,这是我的免责声明!我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2025-01-14 11:05:25

模型名称不应在 URL 中使用,而应在导航属性中使用:

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

如果您想要两者模型和头发颜色,则应使用 $expand:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文