为什么 DomainService 构造函数重载不显示为 DomainContext 构造函数重载?

发布于 2024-11-01 00:33:27 字数 524 浏览 3 评论 0原文

我为 DomainService 类编写了一个重载。问题是,当我重新编译时,它没有显示为我的 DomainContext 的重载。怎么了?这是一个代码示例:

[EnableClientAccess]
public class FoodDomainService : LinqToEntitiesDomainService<FoodEntities>
{
    public FoodDomainService(CultureInfo cultureInfo)
    {
        Thread.CurrentThread.CurrentCulture = cultureInfo;
    }
}

这不起作用:

FoodDomainContext _foodContext = new FoodDomainContext(Thread.CurrentThread.CurrentCulture);

我收到一个错误,没有与之匹配的重载。难道我不被允许这样做吗?我需要某种属性吗?

I wrote an overload for my DomainService class. Problem is, when I recompile, it's not showing up as an overload for my DomainContext. What's wrong? Here is a code sample:

[EnableClientAccess]
public class FoodDomainService : LinqToEntitiesDomainService<FoodEntities>
{
    public FoodDomainService(CultureInfo cultureInfo)
    {
        Thread.CurrentThread.CurrentCulture = cultureInfo;
    }
}

And this doesn't work:

FoodDomainContext _foodContext = new FoodDomainContext(Thread.CurrentThread.CurrentCulture);

I get an error that there is no overload matching that. Am I not allowed to do this? Do I need an attribute of some kind?

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

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

发布评论

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

评论(2

剪不断理还乱 2024-11-08 00:33:27

你不可以这样做。当从 Silverlight 客户端更新上下文时,您并不是直接实例化您的服务。相反,您实例化由 RIA 服务生成的代理类,然后该代理类将调用您的服务。这就是为什么你看不到你的构造函数:因为 RIA 没有在你的代理中生成它。

执行您想要执行的操作还意味着在更新该 FoodDomainContext 类时会与服务器进行往返,但这种情况不会发生,因为您需要完成在执行此操作之前先初始化该对象。

不管怎样,您可以创建一个名为 SetCurrentCulture() 的方法,然后在初始化代理之后调用它。

You are not allowed to do this. When newing up the context from your Silverlight client, you are not directly intantiating your service. Instead, you instantiate a proxy class that was generated by RIA Services, and that proxy class will then call your service. This is why you don't see your constructor: because RIA did not generate it in your proxy.

Doing what you're trying to do would also implicate that there is a round-trip to the server at the time of newing up that FoodDomainContext class, which is not going to happen, because you need to complete the initialisation of that object before you can do so.

Anyway, instead of that you can create a method called SetCurrentCulture() and then call it after initializing the proxy.

日裸衫吸 2024-11-08 00:33:27

这是行不通的,因为DomainContext是在silverlight的客户端代码上生成的,单击查看所有文件夹或跳转到定义,您将看到生成的代码将不包含额外的构造函数。

相反,您必须在域服务中创建一个方法并将信息传递到服务器。

public SetCultreInfo(int lang,...)
{
   ..  set culture info
}

在你的客户端,你应该调用构造函数内部,

public MyDomainContext()
{
    this.SetCulture(....);
}

This will not work because DomainContext is generated on client code of silverlight, click on view all folders or jump to definition and you will see that code generated will not contain your extra constructor.

Instead you will have to create a method in your domain service and pass information to server.

public SetCultreInfo(int lang,...)
{
   ..  set culture info
}

On your client, inside constructor you should call,

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