Skip to content
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

Mono.Data.Sqlite.SqliteException: SQLite error no such table: Employees #1422

Closed
git2013vb opened this issue Mar 16, 2020 · 8 comments
Closed

Comments

@git2013vb
Copy link

git2013vb commented Mar 16, 2020

Hi,
I have this weird error when I use contrib.extension

E 0:00:01.149   Mono.Data.Sqlite.SqliteStatement Mono.Data.Sqlite.SQLite3.Prepare(Mono.Data.Sqlite.SqliteConnection , System.String , Mono.Data.Sqlite.SqliteStatement , UInt32 , System.String& ): Mono.Data.Sqlite.SqliteException: SQLite error
no such table: Employees
  <C++ Error>   Unhandled exception
  <C++ Source>  :0 @ Mono.Data.Sqlite.SqliteStatement Mono.Data.Sqlite.SQLite3.Prepare(Mono.Data.Sqlite.SqliteConnection , System.String , Mono.Data.Sqlite.SqliteStatement , UInt32 , System.String& )()
  <Stack Trace> :0 @ Mono.Data.Sqlite.SqliteStatement Mono.Data.Sqlite.SQLite3.Prepare(Mono.Data.Sqlite.SqliteConnection , System.String , Mono.Data.Sqlite.SqliteStatement , UInt32 , System.String& )()
                :0 @ Mono.Data.Sqlite.SqliteStatement Mono.Data.Sqlite.SqliteCommand.BuildNextCommand()()
                :0 @ Mono.Data.Sqlite.SqliteStatement Mono.Data.Sqlite.SqliteCommand.GetStatement(Int32 )()
                :0 @ ()
                :0 @ Boolean Mono.Data.Sqlite.SqliteDataReader.NextResult()()
                :0 @ Mono.Data.Sqlite.SqliteDataReader..ctor(Mono.Data.Sqlite.SqliteCommand , System.Data.CommandBehavior )()
                :0 @ ()
                :0 @ Mono.Data.Sqlite.SqliteDataReader Mono.Data.Sqlite.SqliteCommand.ExecuteReader(System.Data.CommandBehavior )()
                :0 @ System.Data.Common.DbDataReader Mono.Data.Sqlite.SqliteCommand.ExecuteDbDataReader(System.Data.CommandBehavior )()
                :0 @ System.Data.IDataReader System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(System.Data.CommandBehavior )()
                :0 @ System.Data.IDataReader Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(System.Data.IDbCommand , Boolean , System.Data.CommandBehavior )()
                :0 @ Boolean Dapper.SqlMapper+<QueryImpl>d__140`1[[Employee, desert_edge_server_sharp, Version=1.0.7380.31641, Culture=neutral, PublicKeyToken=null]].MoveNext()()
                :0 @ void System.Collections.Generic.List`1[[Employee, desert_edge_server_sharp, Version=1.0.7380.31641, Culture=neutral, PublicKeyToken=null]].AddEnumerable(System.Collections.Generic.IEnumerable`1[Employee] )()
                :0 @ System.Collections.Generic.List`1[[Employee, desert_edge_server_sharp, Version=1.0.7380.31641, Culture=neutral, PublicKeyToken=null]]..ctor(System.Collections.Generic.IEnumerable`1[Employee] )()
                :0 @ System.Collections.Generic.List`1[Employee] System.Linq.Enumerable.ToList<Employee >(System.Collections.Generic.IEnumerable`1[Employee] )()
                :0 @ System.Collections.Generic.IEnumerable`1[Employee] Dapper.SqlMapper.Query<Employee >(System.Data.IDbConnection , System.String , System.Object , System.Data.IDbTransaction , Boolean , System.Nullable`1[System.Int32] , System.Nullable`1[System.Data.CommandType] )()
                :0 @ Employee Dapper.Contrib.Extensions.SqlMapperExtensions.Get<Employee >(System.Data.IDbConnection , System.Object , System.Data.IDbTransaction , System.Nullable`1[System.Int32] )()
                Main.cs:61 @ void Main._Ready()()

in this line:

Employee _get = con.Get<Employee>(1);

This is the code I'm using:

 string cs = "Data Source==SqliteTest.db";
       using (var con = new SqliteConnection(cs))
       {
           con.Open();
           Employee _get = con.Get<Employee>(1);
           Log.Printi(_get);
       }

and this is my class:

public class Employee
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

here some my imports:

using Mono.Data.Sqlite;
using Dapper.Contrib.Extensions;

If I don't use contrib.extension Dopper work fine.
What I'm missing?

Thank you

@mgravell
Copy link
Member

mgravell commented Mar 17, 2020 via email

@git2013vb
Copy link
Author

git2013vb commented Mar 17, 2020

Nope it is Employee for some reason it(sqlite extension) add an "s" at end.

image

The weird thing is: if I add and "s" in my code the error say "Employeess". it keep add an "s" at end.
It is expected behavior?

@NickCraver
Copy link
Member

This is the default behavior of .Contrib, to override the default plural, please use the [Table] attribute, like this:

[Table("Employee")]
public class Employee
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

In Dapper v3, we aim to make this (and many similar scenarios) continue to work, but also be more customizable.

@git2013vb
Copy link
Author

It. work, I guess the only thing is to update your docs :)
I was expecting the default behavior will be without "attribute" like the [Key] one.

Thank you :)

@git2013vb
Copy link
Author

git2013vb commented Mar 18, 2020

Hi I tried to set the table name as Employees in the database and to let the name Employee in the class.
I have no errors but at same time I have no access to the table even if I use [Table("Employees")].
Any idea of this weird behavior?

Thank you

@NickCraver
Copy link
Member

I don't follow your latest - if your table name is Employees, and the class name is Employee, it should work without attribute. The default behavior is pluralization, the attribute is only to override it. We plan to make this much more expansive in #722, but you shouldn't need anything over current code to make this work.

@git2013vb
Copy link
Author

git2013vb commented May 5, 2020

I don't follow your latest - if your table name is Employees, and the class name is Employee, it should work without attribute. The default behavior is pluralization, the attribute is only to override it. We plan to make this much more expansive in #722, but you shouldn't need anything over current code to make this work.

You right :). I checked again and I missed a name check in DB that was made using nameof(classname) instead "TableName" ;) That was where my error came from.:) I noticed just now after reading your last post. I think I was tired last time hehe.
ps: what about table's name that end with "s"? like.. "Bis" ? They will became "Biss"?

@NickCraver
Copy link
Member

Yep, looks like it's exactly that dumb: https://github.com/StackExchange/Dapper/blob/master/Dapper.Contrib/SqlMapperExtensions.cs#L299

I'll close this out to tidy up, but keep an eye on #722 where we're gonna improve this quite a bit for v3 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants