Note that there are some explanatory texts on larger screens.

plurals
  1. POlinq error Defined default value for hashset
    primarykey
    data
    text
    <p>I Defined this query to return <code>IEnumerable&lt;Estructura&gt;</code> </p> <pre><code> (from d in db.Direccion where d.Activo == true select new Estructura() { IdEstructura = d.IdDireccion, Descripcion = d.Descripcion, IdPadre = 0, lstEstructurasHijos = d.Cliente.Select(C =&gt; new Estructura() { IdEstructura = C.IdCliente, Descripcion = C.Descripcion, IdPadre = C.IdDireccion, lstEstructurasHijos = C.Campana.Select(Ca =&gt; new Estructura() { IdEstructura = Ca.IdCampana, Descripcion = Ca.Descripcion, IdPadre = Ca.IdCliente, lstEstructurasHijos = Ca.Servicio.Select(S =&gt; new Estructura() { IdEstructura = S.IdServicio, Descripcion = S.Descripcion, IdPadre = S.IdCampana, lstEstructurasHijos = new HashSet&lt;Estructura&gt;() }) }) }) } into query select query); </code></pre> <p>And this the class related </p> <pre><code> public class Estructura { public Estructura() { this.lstEstructurasHijos = new HashSet&lt;Estructura&gt;(); } public int IdEstructura { get; set; } public int IdPadre { get; set; } public string Descripcion { get; set; } public IEnumerable&lt;Estructura&gt; lstEstructurasHijos { get;set;} } </code></pre> <p>It throws this error</p> <blockquote> <p><code>System.NotSupportedException</code>: The type '<code>Estructura</code>' appears in two structurally incompatible initializations within a single LINQ to Entities query. A type can be initialized in two places in the same query, but only if the same properties are set in both places and those properties are set in the same order.</p> </blockquote> <p>Why am I doing wrong? Because if i remove the instance Estructura of each element and let the anonymous type the linq works well </p> <p><strong>Update</strong></p> <p>So, I made a few changes in the query but i found this error now</p> <blockquote> <p>could not create '<code>System.Collections.Generic.IEnumerable</code>1`'. Only allow primitive ('como Int32, String y Guid') in this context</p> </blockquote> <p>How can I Defined a default empty <code>hashset</code> for this <code>Ienumerable</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload