On insert, DapperExtensions returns "Invalid object name."

c# dapper dapper-extensions entity-framework sql-server

Question

I'm following the Simple Insert Operation example at https://github.com/tmsmith/Dapper-Extensions#simple-insert-operation

public class Org
{
    public int Id { get; set; }
    public string Name { get; set; }
}

SqlConnection conn = new SqlConnection("...");
conn.Open();
Org org = new Org() { Name = "Just Testing" };
int id = conn.Insert(org);
conn.Close();

This gives me a System.Data.SqlClient.SqlException: Invalid object name 'Org'.

What am I doing wrong here? The table exists and was generated by EF Code First with the standard DbContext subclass containing a public DbSet<Org> Orgs { get; set; }

1
3
10/9/2014 9:00:25 PM

Accepted Answer

The docs state that "POCO names should match the table name in the database. Pluralized table names are supported through the PlurizedAutoClassMapper."

I just didn't read the docs closely enough, my mistake

0
11/4/2018 11:08:24 AM

Popular Answer

In POCO object you can use Table Attribute.

[Table("TableNameInSqlDatabase")]
public class Org
{
   public int Id { get; set; }
   public string Name { get; set; }
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow