-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve documentation on composite types #226
Comments
Thanks, it's true that the docs are a bit light - I'll try to find time to improve them later this year, when the 7.0 work quiets down. In the meantime, I advise looking at the tests to see what's possible or not, and simply to trying things out in your code. Extending/customizing the type handler probably wouldn't be workable; you can generally add type handlers for specific PG types, but composite types are quite different (not just another base type), and it would likely require various changes in the core. You can certainly try though, and we'd accept PRs to Npgsql itself to improve its composite type support. (and thanks for the kind words!) |
Thanks @roji for the prompt follow up as always! I've spent a couple of hours reading the source and here is a brain dump of what I have gleaned so far (I am sharing in the hopes that it may help others and serve as a reference point when updating the docs - but I urge anyone reading this to TEST the observations for themselves). The following files contain the interesting code:
Some of the rules as can be seen in the code:
Long story short: it pretty much just works (even if your CLR type isn't a simple POCO) 👍 My own personal interest in all of this, is using npgsql as a light-weight ORM. I can define stored procedures and functions in Postgres that take/return composite types, then call them easily from C# much like |
@ericmutta it's great that it's all working for you. Yes, for the limitation on constructor parameters, we decided to wait on user feedback before investing more effort into this. I generally believe in succinct docs - docs which are overly long generally don't get read, and confuse users more than they help. As a result, I believe it's better to just show basic usage and list limitations, rather than listing every possible thing that a user may ask, or detailing how things are done under the hood. From my experience, people just try doing their thing (e.g. let's try to map a struct, or fields) - I've rarely seen confusion around these things. [PgIgnore] specifically was briefly raised in #1090, but I haven't seen any actually requests for it. People generally tend to have a POCO corresponding to the PG type, it seems. |
@roji thanks for following up! We are definitely on the same page regarding succinct docs, so I'll defer to you on how best to summarize the composite mapping features whenever you get round to it (meanwhile this issue will be a good reference for curious people like myself) 👍 Regarding |
The npgsql docs briefly mention that you can map CLR classes to composite types in Postgres. But since no example class is given, it is not clear how the mapping works (i.e. what scenarios can or can't be handled). For example, looking at the CompositeHandler.cs code seems to indicate npgsql can map classes with or without explicit constructors...is that correct?
Generally, it would be useful to document the following mapping issues:
I imagine, automatic mapping between CLR classes and Postgres composite types is a huge selling point for many people. I personally would love to know what is or isn't possible so I can take full advantage of this feature. I would also like to know if it is possible to extend/customize the npgsql type handler facility for composite types so I can make up my own rules for mapping.
PS: Postgres is truly amazing and having npgsql so us .NET folks can use Postgres is really cool. My thanks to all who contribute! 🙏
The text was updated successfully, but these errors were encountered: