如何从域服务类调用方法

发布于 2025-01-08 03:24:49 字数 2143 浏览 0 评论 0原文

我再次需要一些有关从 silverlight 调用域服务类方法的帮助。

这在某种程度上与我昨天解决的问题有关。再次感谢! 对于那些感兴趣的人,可以在这里找到我昨天的问题:

使用 ASP.net 会员身份在 silverlight 中获取 aspnet_Users

现在讨论我当前的问题。

我在域服务类中有以下方法,称为 MembershipData

 [RequiresRole("Managers")]
 public void DeleteUser(MembershipServiceUser user)
 {
     Membership.DeleteUser(user.UserName);
 }
  • 此代码来自 kylemc 的教程

现在如何从 Silverlight 中调用此方法?

我从昨天的问题中了解到,

public IEnumerable<MembershipServiceUser> GetAllUsers()

需要通过定义查询来调用,然后运行查询,然后在结果返回时调用 OnGetAllUsersLoaded 。

我不确定的是,由于其返回类型,您是否需要以这种方式调用该方法?

显然 public void DeleteUser(MembershipServiceUser user) 没有返回类型,因此不能以这种方式调用。

似乎不可能做到:

MembershipDataContext context = new MembershipDataContext();
MembershipServiceUser user = new MembershipServiceUser();
user.UserName = "bob";

context.DeleteUser(user);

但是我该如何使用DeleteUser方法呢?

非常感谢任何帮助。

亲切的问候,

尼尔

更新

感谢您提供的信息高科技。我还有一个问题需要解决。也许我仍然没有做正确的事情。

我现在正在创建 MembershipServiceUser 的一个新实例,我们将其称为 msu。 然后分配 msu.UserName 和 msu.Email 用户详细信息,然后调用

context.MembershipServiceUsers.Remove(msu) 

where context 是我的 MembershipData 域服务上下文,我已经检查过它

context MembershipServiceUsers results 

确实有我的用户信息。然而,我收到以下错误

“指定的实体不包含在此 EntitySet 中。”

我确信 msu 中的数据是正确的,那么关于为什么我会收到此错误有什么想法吗? 非常感谢

更新 2

我是否走在正确的轨道上,类似于下面的内容......

MembershipServiceUser usr = (from a in context.MembershipServiceUsers
                                     where a.UserName == "bob"
                                     select a).First();

context.MembershipServiceUsers.Remove(usr);
context.SubmitChanges(DeleteUser_completed, null);

还是这样?因为在我的回调中DeleteUser_completed(SubmitOperation so) so.HasError = true ChangeSet 也是如此 -> RemovedEntities = 1,但 EntitiesInError 的结果是“枚举没有结果”

再次感谢您帮助引导我走向正确的方向。

Once again I am in need of some assistance with regard to calling a Domain Service class method from silverlight.

This ties in somewhat to my question of yesterday which was solved. Thanks again!
For those who are interested, my question of yesterday can be found here:

Using ASP.net membership to get aspnet_Users in silverlight

Now onto my current question.

I have the following method in Domain Service Class called MembershipData

 [RequiresRole("Managers")]
 public void DeleteUser(MembershipServiceUser user)
 {
     Membership.DeleteUser(user.UserName);
 }
  • This code is from kylemc's tutorial

Now how do I call this method from within Silverlight?

I understand from yesterday's question that

public IEnumerable<MembershipServiceUser> GetAllUsers()

needs to be called by defining the query, then running the query and then calling OnGetAllUsersLoaded when the the results return.

What I am unsure of is, Do you need to call the method in this way because of its return type?

Obviously public void DeleteUser(MembershipServiceUser user) has no return type so cannot be called in this way.

It does not seem to be possible to do:

MembershipDataContext context = new MembershipDataContext();
MembershipServiceUser user = new MembershipServiceUser();
user.UserName = "bob";

context.DeleteUser(user);

But then how do I use the DeleteUser method?

Any assistance is greatly appreciated.

Kind regards,

Neill

Update

Thanks for the info HiTech. I still have one issue I need to solve. Perhaps I am still not doing something correctly.

I am now creating a new instance of MembershipServiceUser, lets call it msu.
Then assigning msu.UserName and msu.Email the user details, and after that calling

context.MembershipServiceUsers.Remove(msu) 

where context is my MembershipData domain service context, and I have checked that

context MembershipServiceUsers results 

does have my user info. I then however get the following error

"The specified entity is not contained in this EntitySet."

I am positive the data in msu is correct, so any ideas as to why I am getting this error?
Many thanks

Update 2

Am I on the right track with something like the following...

MembershipServiceUser usr = (from a in context.MembershipServiceUsers
                                     where a.UserName == "bob"
                                     select a).First();

context.MembershipServiceUsers.Remove(usr);
context.SubmitChanges(DeleteUser_completed, null);

Or is this way off? because in my callback DeleteUser_completed(SubmitOperation so)
so.HasError = true
while so's ChangeSet -> RemovedEntities = 1, but so's EntitiesInError's result is "enumeration yielded no results"

Once again thanks for helping steer me in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

半衬遮猫 2025-01-15 03:24:49

RIA 服务的工作原理是创建更改集(字面意思是一组更改)并将这些更改发送到服务器。做CRUD的方法更像是实体框架,而不是直接的方法调用。

在客户端,您将在域上下文的 User 集合上调用 Remove 方法。

在接收端,它会执行所有更改并询问:

  • 问:“这是对象删除吗?”
  • 答:是的...
  • 问:“它是什么类型的物体?”
  • A. MembershipServiceUser
  • 问:“我们是否有一个名为“Delete”的方法,它采用 MembershipServiceUser 参数?”
  • 答:是的...

然后它使用变更集中的对象调用该方法...

RIA services works by creating a change set (literally a set of changes) and sending just those changes to the server. The methods to do CRUD are more like Entity Framework, not direct method calls.

On the client side you will call the Remove method on the domain context's User collection.

On the receiving side it goes through all the changes and says:

  • Q. "Is this an object deletion?"
  • A. Yes...
  • Q. "What object type is it?"
  • A. MembershipServiceUser
  • Q. "Do we have a method called Delete that takes a MembershipServiceUser parameter?"
  • A. Yes...

It then calls that method with the object from the changeset...

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