最近,我一直在使用通过 Web 服务与服务器交互的 WPF 应用程序。我目前正在尝试使用 Telerik OpenAccess 来处理数据库并为我的 WPF 应用程序创建服务。
然而,有一个问题我需要解决,而且有些问题我无法让它工作。
数据库中的关系似乎不起作用。
我尝试使用 WCF Endpoint Service
和 Data Service for .Net 4
。两者都有向数据库创建记录的功能,如下所示:
service.createRecord(Record x)
我的数据库关系只是有一个多对多模型,如 ff:
--------------
RecordID
--------------
1
2
3
---------------
RecordTag
---------------
RID | TID |
---------------
1 1
2 1
3 1
---------------
---------------
Tag
---------------
TID
---------------
1
2
3
在我的代码中,我执行了 ff:
Service.Record r = new Service.Record(){ [...] };
r.Tags.Add(new Service.Tag(){ [...] };
结果是:
1. WCF Endpoint Service无法添加标签,因为 r 为空。
2.
.Net 4 的数据服务仅添加
Record`,没有任何标签
有人知道如何解决这个问题吗?任何答案或提示将不胜感激!
Recently I have been working with WPF Applications that interact with server through Web Services. I am currently try to use Telerik OpenAccess to works with the database and create services for my WPF application.
However there's one problem I need to resolve and some how I can't get it to work.
The relationships in database doesn't seem to works.
I've tried to use WCF Endpoint Service
and Data Service for .Net 4
. Both have function to create a record to database like this:
service.createRecord(Record x)
My database relationship is simply have a Many to Many model like ff:
--------------
RecordID
--------------
1
2
3
---------------
RecordTag
---------------
RID | TID |
---------------
1 1
2 1
3 1
---------------
---------------
Tag
---------------
TID
---------------
1
2
3
In my code, I did the ff:
Service.Record r = new Service.Record(){ [...] };
r.Tags.Add(new Service.Tag(){ [...] };
Result is:
1. WCF Endpoint Servicedoesn't able to add Tags because r was null.
2.
Data Service for .Net 4was only add
Record` without any Tags
Anyone know how to solve this problem? Any answer or hints would be appreciated!
发布评论
评论(2)
在 WCF 数据服务案例中,仅设置属性是不够的。您需要让上下文知道您要添加链接(关系)。这是因为实体不执行财产级别跟踪。
http://msdn.microsoft.com/en-us/library/dd756361.aspx
尤其是关系链接的部分。
In the WCF Data Services case, just setting the proeprty is not enough. You need to let the context know that you want to add a link (relationship). This is because the entities do not perform property level tracking.
http://msdn.microsoft.com/en-us/library/dd756361.aspx
Especially the part about relationship links.
您的意思是您无法将记录返回到客户端吗?如果是这样,您是否在端点服务中的数据(记录等)上使用了 DataContractAttribute?
Do you mean that you can't get Record back on client? if so, have you use DataContractAttribute on your data (Record etc.) in your endpoint service?