.Net WCF RIA Services parametrizó el bloqueo del método NameValue
Frecuentes
Visto 108 veces
0
Agregué un método de servicio de dominio RIA para devolver un NameValuePair simple de dos propiedades de una tabla (y filtrado en un valor clave).
Se compila bien, pero explota cada vez sin dar un error útil.
¿Qué me estoy perdiendo? (probablemente algo realmente obvio)
p.ej:
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);
}
Sencillo NombreValorPar Código:
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;
}
}
Actualizar:
Intenté devolver una consulta en una lista estática de objetos NameValuePair y eso funciona bien (pero no es útil).
1 Respuestas
1
Intenté esto aquí y obtuve el error: base {System.SystemException} = {"Only parameterless constructors and initializers are supported in LINQ to Entities."}
Entonces, primero debe cambiarlo para crear el objeto, luego pasar los valores de propiedad:
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};
}
contestado el 22 de mayo de 12 a las 20:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas silverlight wcf-ria-services silverlight-5.0 or haz tu propia pregunta.
+1: Este fue realmente el problema... Tuve un segundo error de datos no relacionado que estaba causando un bloqueo incluso cuando cambié a este formato. Gracias por reforzar el "solo puede tener un constructor predeterminado" ocurrencia :) - Codificación ido