实体框架似乎正在改变poco对象的真实名称

时间:2016-08-03 00:12:27

标签: c# sql-server entity-framework

我有一个数据库(sql server)表名:InternInterest

然后在我的代码中我只有InternInterest这个词,无论是作为属性,还是存储库或工作单元的一部分,但是在ninject旋转并且项目运行之后不知何故抛出此错误:

{"One or more validation errors were detected during model generation:\r\n\r\nInterestIntern: Name: The EntitySet 'InterestIntern' with schema 'dbo' and table 'InternInterest' was already defined. Each EntitySet must refer to a unique schema and table.\r\n"}

One or more validation errors were detected during model generation:

InterestIntern: Name: The EntitySet 'InterestIntern' with schema 'dbo' and table 'InternInterest' was already defined. Each EntitySet must refer to a unique schema and table.

在我的项目中根本就没有InterestIntern这样的东西,怎么会发生这种情况呢?

所以在控制器(web api)中就是这个

[Route("api/assignment/GetAssignments")]
public List<Assignment> GetAssignments()
{
   var result = _UnitOfWork.AssignmentsRepository.Get();
   return result;
}

其中GenericRepository Get方法

 public virtual List<TEntity> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, params Expression<Func<TEntity, object>>[] includes)
    {
        IQueryable<TEntity> query = _DbSet;

        foreach (Expression<Func<TEntity, object>> include in includes)
            query = query.Include(include);

        if (filter != null)
            query = query.Where(filter);

        if (orderBy != null)
            query = orderBy(query);

        return query.ToList();
    }

我正在看

    `Message    "The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe."    string`

刷新:

“抛出了'System.Threading.ThreadAbortException'类型的异常。”}

现在好像我收到了这个错误

“System.TypeInitializationException

附加信息:'System.Data.SqlClient.SqlConnection'的类型初始值设定项引发了异常。

仍在那return query.ToList();

0 个答案:

没有答案