How to generate models for a PostgreSQL database with composite types?

Hello, redditors. I find myself right now struggling to find data related to how to properly manage my DataBase and how should I work with composite types in C#.

​

I'm building an application where I removed the usage of extra tables implementing that data inside composite types, a 2D Array which each item in those arrays might have 1 or 2 attributes which might be an array or a 2D array as well. How should I create my model if I choose to go with ORM, tried using the dotnet ef scaffold but it couldn't map my composite type initial columns at my tables. I couldn-t work it out to use my composite type. Searched for NHibernate and I've been struggling to create my models.

var connectionStr = "//database connection//";

var model = AutoMap.AssemblyOf<TblAccount>()
.Where(t => t.Namespace == "TestApp.Data");

ISessionFactory sessionFactory = Fluently.Configure()            .Database(PostgreSQLConfiguration.Standard.ConnectionString(connectionStr))
.Mappings(m => m.AutoMappings.Add(model))
.BuildSessionFactory();

I tried to create my own models and make a test with the previous code but I don't see new files being created, or anything at all. I don't know if it's working as expected as I don't know what happens after the code runs, or I'm missing something. I've spent my last 3 hours looking for any kind of book or reference in order to figure out what to do next, I find a couple of answer in stackoverflow and I'm missing the context, they are senseless to me. The simplest way to solve this is to create a extra tables with FK to my Account table and do the same with the others and their composite types which are all arrays, storing a few more arrays. But in my thought process I think that creating the tables are a bit of a waste in memory as their data will be only relevant to the parent where they are been stored. It's a management system I'm building for a specific situation. I might be wrong, it might make sense.

I only want to know this is working or a way work it out, test my .net to psql connection, be able to use CRUD operations on my tables and then I'll move into building the APIs.

Does anyone know a resource to get pass this problem? A book with implementations of PostgreSQL and C#, composite types and building a WEB Api around it would be the ideal case scenario for me. Any other ORM with support to composite types and a richer documentation, perhaps. Anything is welcome!!

Posted Mar 22, 2021, 9:05 PM UTC

00

No comments yet

Nobody commented on this post, or the comments weren't captured.