Entity Framework Core postgresql Array Type Mapping not working

夙愿已清 提交于 2020-12-06 12:37:48

问题


I have a strange problem, maybe it is something that I'm missing out, but I have the following LINQ Lambda query:

var ss = ctx.ShipZones.SelectMany(
                z => ctx.ShipDecks,
                (z, d) =>
                    new
                    {
                        Zone = z.ZIndex,
                        Deck = d.DIndex,
                        Value = ctx.Tags
                            .AsExpandable()
                            .Include(s => s.TagSettings.Device.System)
                            .Where(s =>
                                 s.TagSettings.TagTypeId == 171
                                 && s.TagSettings.Device.System.Id == z.Id
                                 && s.TagSettings.Device.ControlArea.Contains(d.Id)

                                    )
                            .Average(s => s.Value)

                    }
                ).ToList();

According to this article, this should be translated to this:

SELECT z.z_index AS "Zone", d.d_index AS "Deck", (
  SELECT AVG(t.value)
  FROM tags_current_data AS t
  INNER JOIN tags_settings AS t0 ON t.tag_id = t0.id
  INNER JOIN systems_devices AS s ON t0.device_id = s.id
  INNER JOIN systems AS s0 ON s.system_id = s0.id
  WHERE ((t0.tag_type_id = 171) AND (s0.id = z.id)) AND (d.id = ANY(s.control_area))) AS "Value"
FROM zones AS z
CROSS JOIN decks AS d

But somehow, the translated query is like this:

SELECT z.z_index AS "Zone", d.d_index AS "Deck", (
  SELECT AVG(t.value)
  FROM tags_current_data AS t
  INNER JOIN tags_settings AS t0 ON t.tag_id = t0.id
  INNER JOIN systems_devices AS s ON t0.device_id = s.id
  INNER JOIN systems AS s0 ON s.system_id = s0.id
  WHERE ((t0.tag_type_id = 171) AND (s0.id = z.id)) AND (TRUE = FALSE)) AS "Value"
FROM zones AS z
CROSS JOIN decks AS d

The difference is where it should be d.id = ANY(s.control_area) it is TRUE = FALSE

Can anyone tell me what am I doing wrong?

Thanks in advance,

Julian Dimitrov


回答1:


I was able to solve my problem. It is in this issue.

Basically:

It was in the entities configuration. The ControlArea property in the Device entity was of type List<long>. When I changed it to long[] (long array) it worked!



来源:https://stackoverflow.com/questions/64045636/entity-framework-core-postgresql-array-type-mapping-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!