jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DbParameterGenerator dictionary handling

mcmikecreations opened this issue · comments

Describe the bug

I've been trying to use this library with the PostgreSQL provider and a Dictionary<string, object> instead of a DynamicObject or a type, but the dictionary check here doesn't take into account, that all parameters and fields in Postgre are lowercase and the dictionary keys may be uppercase. I'm not sure if this is exclusive to this provider, but it would be nice to have a ToLower() call inside Insight.

Steps to reproduce

  1. I created a postgres function with a lowercase parameter
  2. I created a dictionary with uppercase keys and called SingleAsync<MyType>(myName, myDictionary);
  3. I got an error that a parameter (with lowercase) must be present

Expected behavior

The TryGetValue treats keys as lowercase

  • Dotnet version: [netstandard2.0]
  • Database: [PostgreSQL]
  • Library version: [6.3.10]

Another issue I'm having is that it sees the parameter of type geometry as enumerable, tries to convert it using ListParameterHelper.ConvertListParameter(p, value, cmd); at DbParameterGenerator.cs and fails, because it thinks it's a table-valued parameter which PostgreSQL provider doesn't support.

If you want your dictionary to be case-insensitive, use a case-insensitive dictionary. For example, the Insight FastExpando is a fast, expandable dictionary that uses case-insensitive compare:

    public sealed class FastExpando : DynamicObject, IDictionary<string, object>
    {
        #region Private Fields
        /// <summary>
        /// The internal data structure.
        /// </summary>
        private IDictionary<string, object> data = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        #endregion

You can probably use FastExpando, or create your dictionary with the proper StringComparer.

Re: geometry class, I'll go look at your other issue. Geometry classes kinda suck in the ADO.NET framework but we'll see what we can do.

Gonna mark this as closed because I think case-insensitive dictionary solves your problem, but feel free to reopen.