0

我添加了一个 RIA 域服务方法以从表中返回两个属性的简单 NameValuePair(并根据键值进行过滤)。

它编译得很好,但每次都炸毁而没有给出有用的错误。

我错过了什么?(可能很明显)

例如:

    public IQueryable<NameValuePair> GetNameValues(int keyId)
    {
        // NOTE: I can breakpoint here and the correct keyId is passed
        // it blows up on returning from this method
        return from p in this.ObjectContext.NameTable
                where p.KeyId == keyId
                select new NameValuePair(p.NameValue, p.NameType);
    }

简单的 NameValuePair代码:

public class NameValuePair
{
    [Key]
    public string Name { get; set; }
    public string Value { get; set; }

    public NameValuePair()
    {
    }

    public NameValuePair( string name, string value)
    {
        this.Name = name;
        this.Value = value;
    }
}

更新:

我尝试在 NameValuePair 对象的静态列表上返回一个查询,并且效果很好(但没用)。

4

1 回答 1

1

我在这里尝试了这个并得到了错误:base {System.SystemException} = {"Only parameterless constructors and initializers are supported in LINQ to Entities."} 所以你必须先改变它来创建对象,然后传递属性值:

public IQueryable<NameValuePair> GetNameValues(int keyId)
{
    return from p in this.ObjectContext.NameTable
            where p.KeyId == keyId
            select new NameValuePair {Name = p.NameValue, Value = p.NameType};
}
于 2012-05-22T18:23:41.927 回答