Only parameterless constructors and initializers are supported in LINQ to Entities

后端 未结 14 1408
暗喜
暗喜 2020-11-27 15:27

I have this error in this linq expression :

var naleznosci = (from nalTmp in db.Naleznosci
                              where nalTmp.idDziecko == idDziec
           


        
14条回答
  •  盖世英雄少女心
    2020-11-27 16:07

    Also, if you want to use a constructor with multiple objects to initialize, you might get error if no values are returned by Linq.

    So you might want to do something like this:

    (from x in table_1
       join y in table_2
       on x.id equals y.id
       select new {
       val1 = x,
       val2 = y
    })
    .DefaultIfEmpty()
    .ToList()
    .Select(a => new Val_Constructor(a.val1 != null ? a.val1 : new Val_1_Constructor(),
                                a.val2 != null ? a.val2 : new Val_2_Constructor()))
    .ToList();
    

提交回复
热议问题