mikependon / RepoDB

A hybrid ORM library for .NET.
Apache License 2.0
1.7k stars 125 forks source link

Question: New setup, cannot get past MissingFieldsException #1148

Open moxplod opened 1 year ago

moxplod commented 1 year ago

Hi, I am new to RepoDB. Trying it with Postgres. I might be doing something obvious that is wrong as I cannot get it to work. I keep getting this error. Please let me know if there is something I need to try or how to debug this.

RepoDb.Exceptions.MissingFieldsException There are no database fields found for table 'Account'. Make sure that the target table 'Account' is present in the database and/or at least a single field is available.

Here is my setup:

Setup:

static RepoDbRepository()
    {
        GlobalConfiguration
            .Setup()
            .UsePostgreSql();
    }

Trying this test:


[Fact]
        public void AccountInsertTest()
        {
            // Initialize the library for global initialization
            var repoDb = new RepoDbRepository<Account>(false);

            using var connection = DatabaseFactory.CreateSqlConnection(false);
            var id = connection.Insert<Account, long>(
                new Account
                {
                    AccountStatus = AccountStatus.Active,
                    AccountType = AccountType.Admin,
                    DateCreated = DateTime.UtcNow,
                    DateUpdated = DateTime.UtcNow
                });
            id.ShouldNotBe(0);
        }

Throws the exception:

image

Here is the table:


CREATE TABLE account( 
    id bigserial PRIMARY KEY,
    type varchar(36) NOT NULL,
    status varchar(36) NOT NULL,
    companyname varchar(128),
    stripecustomerid varchar(36),
    datecreated timestamp NOT NULL,
    dateupdated timestamp NOT NULL);
Sindrenj commented 1 year ago

I'm stuck with this too.. I've never been able to use RepoDB with my database. All my tables have snake_casing so I use Map() but still it doesen't work. It also looks like repodbs table-resolver is case-sensitive I've manage to make thisisatable to work while ThisIsATable does not work.. Map("text") is case-sensitive it seems. And if you are lucky that the table is found then the column/properties are not matched if the column name does not match the property in casing. Doesen't make sense when SQL normally is case-insensitive.. But maybe Postgresql is case-sensitive on this.. I don't know..

@moxplod Try setting Map("account") i believe that Repodb is looking for "Account" not "account" in your db because the c# object has its first letter as uppercase..