by时npgsql数据类型未知

by时npgsql数据类型未知

本文介绍了使用group by时npgsql数据类型未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表:

CREATE TABLE "book"
(
  "id" serial PRIMARY KEY,
  "ean_number" TEXT NULL,
  "title" TEXT NULL
);

CREATE TABLE "e_book"
(
  "id" serial PRIMARY KEY,
  "ean" TEXT NULL,
  "title" TEXT NULL,
  "format" VARCHAR(255) NOT NULL,
  "physical_book_ean" TEXT NULL
);

从书本到电子书之间存在一对多或没有关系。

There is a one to many or none relationship from book to e_book.

我想在我的代码中运行这样的查询:

I want to run a query like this in my code:

var q = "select b.*, array_agg(e) ebooks from book b " +
         "left join e_book e on e.physical_book_ean = b.ean_number " +
         "group by b.id";

using (var cmd = new NpgsqlCommand(q, conn))
using (var reader = cmd.ExecuteReader())
    while (reader.Read())
    {
        //read data
    }

array_agg列电子书来了< unknown>

The array_agg column ebook comes up as content type <unknown>

如何定义内容类型以便可以读取? / p>

How do I define the content type so I can read it?

推荐答案

这是作为github问题打开的:

This was opened as a github issue: https://github.com/npgsql/npgsql/issues/2510

答案如此处给出:

第二,您需要在连接字符串上传递LoadTableComposites = true标志,告诉Npgsql加载所有复合类型-包括与表相对应的复合类型。默认情况下,Npgsql不会执行此操作,因为表的数量可能很大,并且在某些情况下会影响启动性能。

Second, you will need to pass the LoadTableComposites=true flag on the connection string, telling Npgsql to load all composite types - including those which correspond to tables. Npgsql doesn't do that by default since the number of tables can be massive and affect startup performance in some cases.

这篇关于使用group by时npgsql数据类型未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 23:17