[英]Cannot get records with entity framework
I have an SqLite db which have category table. 我有一个具有类别表的SqLite数据库。 Category table has 3 columns, Id: int, name: varchar, and ObjectID: int
类别表有3列,分别是ID:int,名称:varchar和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
: 现在当我尝试使用context.Categories获取类别时,我收到
System.Data.SQLite.SQLiteException
:
SQL logic error or missing database\\r\\nno such column: Extent1.Object_Id
SQL逻辑错误或缺少数据库\\ r \\ n没有这样的列: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. 我不知道Object_Id的来源。 I don't have such column in db and I don't use such name in my whole project.
我在db中没有这样的列,并且在我的整个项目中都没有使用这样的名称。
I use System.Data.SQLite 我使用System.Data.SQLite
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? EntityFramework试图选择一个不存在的列?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.