简体   繁体   English

实体框架核心 postgresql 数组类型映射不起作用

[英]Entity Framework Core postgresql Array Type Mapping not working

I have a strange problem, maybe it is something that I'm missing out, but I have the following LINQ Lambda query:我有一个奇怪的问题,也许这是我遗漏的问题,但我有以下 LINQ Lambda 查询:

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不同之处在于它应该在d.id = ANY(s.control_area)它是TRUE = FALSE

Can anyone tell me what am I doing wrong?谁能告诉我我做错了什么?

Thanks in advance,提前致谢,

Julian Dimitrov朱利安·迪米特洛夫

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> . Device实体中的ControlArea属性是List<long>类型。 When I changed it to long[] (long array) it worked!当我将其更改为long[] (长数组)时,它起作用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM