我已经阅读了所有可以找到的帖子和文章,并且没有人解决EF的这个非常奇怪的问题。
我有一个映射表调用的上下文" Thing"。
[Table("Tbl_Thing")]
public class Thing
{
[Column("dbThingNumber"),Key, DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
public Decimal ThingId { get; set; }
[Column("dbBatch")]
public int? BatchId { get; set; }
[Column("dbPeople")]
public int? People { get; set; }
[Column("dbFileID")]
[StringLength(50)]
public string FileName { get; set; }
[Column("dbFilePath")]
public int? PathId { get; set; }
}
当我查询表格时," Thing"在主屏幕上,设置,群组等等,就像一个魅力:
class ThingService{
private Context context;
public ThingService(Context context)
{
this.context = context;
}
public List<Thing> GetThingsByPeopleId(int id)
{
return context.Thing.Where(x=>x.People == id);
}
}
所以在另一堂课中,我有这个。
var thingService = new ThingService(new Context());
var thingsByPeople = thingService.GetThingsByPeopleId(4);
是的,这里有岩石和工作。
但是当我在一个名为&#34; ThingsArticles&#34;的类中做同样的事情(相同的方法,相同的id,相同的上下文和相同的过程)时我明白了:
Invalid column name dbFilePath.
dbFilePath不是FK,不是AU ......只是一个普通的INTEGER列,这里是脚本:
CREATE TABLE [dbo].[Tbl_Thing](
[dbThingNumber] [decimal](10, 0) IDENTITY(1,1) NOT NULL,
[dbBatch] [int] NULL,
[dbApplication] [int] NULL,
[dbFileID] [varchar](50) NULL,
[dbFilePath] [int] NULL,
) ON [PRIMARY]
这个错误有点疯狂,因为它存在于其他地方(clases)有效,而其他地方没有没有探索原因,而且这是唯一失败的列。
我在工作班的哪个地方:
var thingService = new ThingService(new Context());
var thingsByPeople = thingService.GetThingsByPeopleId(4);// exactly the same, i just copy and pasted it.
可能会发生什么?它还有什么东西让我失踪?
更新
实体框架版本:6
更新2:
我也直接使用上下文,同样的事情发生了:
context.Thing.Where(x=>x.People == 2);// the same error is throw
我如何称呼ThingArticle:
class Article {
private Context context;
public Article(Context context)
{
this.context = context;
}
public List<Article> GetArticleInfo(int id)
{
var thingService = new ThingService(context);
var PeopleThings = thingService.GetThingsByPeopleId(id);// here error throw
// and more code...
}
}