0

I have an SqLite db which have category table. Category table has 3 columns, Id: int, name: varchar, and ObjectID: int

I wrote entity for this table:

class Category
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int ObjectId { get; set; }
}

and I also have a context:

class DEContext: DbContext
{
    public DbSet<Category> Categories { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions
            .Remove<PluralizingTableNameConvention>();
    }
}

Now when I try to get categories with context.Categories I receive System.Data.SQLite.SQLiteException:

SQL logic error or missing database\r\nno such column: Extent1.Object_Id

The query looks like:

SELECT
    [Extent1].[Id] AS [Id],
    [Extent1].[Name] AS [Name],
    [Extent1].[ObjectId] AS [ObjectId],
    [Extent1].[Object_Id] AS [Object_Id]
FROM [Category] AS [Extent1]} System.Data.Entity.DbSet<Category> 

I don't know where the Object_Id is from. I don't have such column in db and I don't use such name in my whole project.

I use System.Data.SQLite

PoLáKoSz
  • 355
  • 1
  • 6
  • 7
szaman
  • 6,666
  • 13
  • 53
  • 81

1 Answers1

3

Ok, my mistake. I had List of categories defined in my Object entity, and that was causing the problem.

Related questions:

Entity Framework trying to retrieve non existent column

EntityFramework tries to select a none existing column?

Community
  • 1
  • 1
szaman
  • 6,666
  • 13
  • 53
  • 81