指定默认参数Silverlight RIA服务类

时间:2013-09-05 15:07:29

标签: c# silverlight wcf-ria-services ria

每个人,

如何在Silverlight上下文类中指定默认参数?以下是我要完成的任务:

public partial class MyContext : LinqToEntitiesDomainService<MyConnectionString>
{
    //other functionality omitted for simplicity

    public IQueryable<Foo> GetFoo(int id, string optional = "")
    {
        //foo stuff
        return this.ObjectContext.Foo.Where( p => p.id = id);
    }

}

我将db表导入到edmx文件中 现在在生成的MyContext.g.cs文件中,默认参数不被视为默认参数 相反,这就是生成的内容:

public EntityQuery<Foo> GetFooQuery(int id, string optional)
{
    //stuff omitted
}

我不能使用像GetFooQuery(1)这样的单个参数来调用上面的方法。它给了我一个编译时错误,说明没有这样的方法接受单个参数。

它是如何工作的?在这种情况下如何指定默认参数?

1 个答案:

答案 0 :(得分:0)

您不能使用此签名(一个整数参数)。

因为WCF RIA服务(域服务)在服务器端代码上编译正常,但生成到客户端的代码包含非可选的参数,因此全部想要使用可选参数的默认值的客户端代码无法编译。