0

I'm migrating my project to use newest Npgsql library (v 8.0.2). I used this construction to map C# type to the Postgres type:

var nameTranslator = new NpgsqlSnakeCaseNameTranslator();;
NpgsqlConnection.GlobalTypeMapper.MapComposite<StockPriceDto>("stock_item_price", nameTranslator);

Now NpgsqlConnection.GlobalTypeMapper is marked as obsolete, so I would like to find an alternative for it with Fluent NHibernate configuration. In postgres I have a stock_item_price type which is almost one-to-one mapping with StockPriceDto type properties (the only differerence is naming convention). In database i have procedure like:

CREATE OR REPLACE PROCEDURE public.stock_price_save(list stock_item_price[]) ...

It is called in the code:

command.CommandText = "Call stock_price_save(@list)";
var listParam = command.CreateParameter();
listParam.ParameterName = "list";
listParam.DbType = System.Data.DbType.Object;
listParam.Value = data; //IList<StockPriceDto>
command.Parameters.Add(listParam);
command.ExecuteNonQuery();

It works perfect with NpgsqlConnection.GlobalTypeMapper. I cannot find the way to map the type StockPriceDto to stock_item_price in Fluent NHibernate. Anyone done it before?

The error is: Writing values of 'System.Collections.Generic.List`1[[X.StockPriceDto, X, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..

1 Answer 1

0

As the obsoletion message says, the replacement for GlobalTypeMapper is to use NpgsqlDataSource (please read the docs for more details). NHibernate would have to add support for NpgsqlDataSource - until then you can suppress the obsoletion message and continue to use GlobalTypeMapper.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, it seems to be a good solution to wait for NHibernate to support NpgsqlDataSource. Perhaps I should submit issue there...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.