我正在尝试在我的机器上安装的TeamCity上运行我的测试.
System.InvalidOperationException:实体框架提供程序类型" 为" 'ADO.NET提供程序无法加载.确保提供程序程序集可用于正在运行的应用程序.
System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServerVersion=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'System.Data.SqlClient
我没有参考System.Data.Entity任何我在codeplex上建议升级到EF6的项目.
所以,我不知道为什么我会得到这个例外.当我从VS运行测试时,我没有得到任何这样的异常.
我确实尝试将CopyLocal设置为false然后再次设置为true ..但这似乎也不起作用.
更新
我的app.config有以下内容.这会导致一些我不理解的行为吗?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我在teamcity中得到以下stacktrace.
[MSTest] IntegrationTests.CrudTest+QuestionTest.Create
[03:59:11][IntegrationTests.CrudTest+QuestionTest.Create] Initialization method IntegrationTests.CrudTest+QuestionTest.Initialize threw exception. System.InvalidOperationException: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用EF6更新记录.首先找到记录,如果存在,则更新它.这是我的代码: -
var book = new Model.Book
{
BookNumber = _book.BookNumber,
BookName = _book.BookName,
BookTitle = _book.BookTitle,
};
using (var db = new MyContextDB())
{
var result = db.Books.SingleOrDefault(b => b.BookNumber == bookNumber);
if (result != null)
{
try
{
db.Books.Attach(book);
db.Entry(book).State = EntityState.Modified;
db.SaveChanges();
}
catch (Exception ex)
{
throw;
}
}
}
Run Code Online (Sandbox Code Playgroud)
每次我尝试使用上面的代码更新记录时,我收到此错误: -
{System.Data.Entity.Infrastructure.DbUpdateConcurrencyException:存储更新,插入或删除语句影响了意外的行数(0).自实体加载后,实体可能已被修改或删除.刷新ObjectStateManager entrie
经过一个小时的搜索后,我无法相信找不到合适的解决方案.我正在关注Entity Framework 6.0上的这篇文章,它简单介绍了Code First.我创建了项目并安装了最新的EF Nuget包以供项目编译.我还验证了我安装了Visual Studio 2013附带的Microsoft SQL Server 2012 Express LocalDB.我的本地计算机上没有安装任何其他SQL实例.程序运行并将条目添加到数据库并在控制台中输出.但是,当文章说"检查你的localdb"时,它没有说明如何!我没有在项目文件夹下看到任何'.mdf'或'.ldf'文件.我尝试了将Visual Studio的Server Explorer连接到LocalDB的各种方法.向导无法找到(localdb)或找不到服务器资源管理器中的任何提供程序来接受连接字符串,就像(localdb)\v11.0;Integrated Security=true;我在StackOverflow中询问了几个地方但没有答案工作或标记为答案.请帮忙,这不一定是令人沮丧的!
将Visual Studio Server Explorer连接到LocalDB的步骤是什么?
server-explorer visual-studio localdb entity-framework-6 sql-server-2012-localdb
我正在尝试使用Code First构建一个EF实体,并EntityTypeConfiguration使用流畅的API.使用Unique Constraint创建主键很容易,但不是这样.我看到旧帖子建议为此执行本机SQL命令,但这似乎打败了目的.这可能与EF6有关吗?
我刚刚开始使用单元测试和TDD.我之前已经涉足过,但现在我决心将它添加到我的工作流程并编写更好的软件.
我昨天问了一个问题,包括这个问题,但这似乎是一个问题.我坐下来开始实现一个服务类,我将用它来从控制器中抽象出业务逻辑,并使用EF6映射到特定的模型和数据交互.
问题是我已经阻止了自己,因为我不想在存储库中抽象EF(它仍然可以在服务之外用于特定查询等)并且想测试我的服务(将使用EF Context) .
在这里我想是问题,有没有意义这样做?如果是这样的话,人们如何在野外做到这一点,因为IQueryable引起的漏洞抽象以及Ladislav Mrnka关于单元测试主题的许多重要帖子都不是直截了当的,因为Linq提供商在处理内存时存在差异与特定数据库相关的实现.
我想测试的代码看起来很简单.(这只是虚拟代码,试图理解我在做什么,我想用TDD驱动创建)
上下文
public interface IContext
{
IDbSet<Product> Products { get; set; }
IDbSet<Category> Categories { get; set; }
int SaveChanges();
}
public class DataContext : DbContext, IContext
{
public IDbSet<Product> Products { get; set; }
public IDbSet<Category> Categories { get; set; }
public DataContext(string connectionString)
: base(connectionString)
{
}
}
Run Code Online (Sandbox Code Playgroud)
服务
public class ProductService : IProductService
{
private IContext _context;
public ProductService(IContext dbContext)
{
_context = dbContext;
}
public IEnumerable<Product> GetAll() …Run Code Online (Sandbox Code Playgroud) 有没有办法使用代码优先在属性/列上创建索引,而不是使用新的IndexAttribute?
当我处于一个独立的场景并从客户端获取dto时,我将其映射到一个实体以保存它,我这样做:
context.Entry(entity).State = EntityState.Modified;
context.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
那是什么呢 DbSet.Attach(entity)
或者当EntityState.Modified已经附加实体时,我为什么要使用.Attach方法?
Sql server表:
SomeId PK varchar(50) not null
OtherId PK int not null
Run Code Online (Sandbox Code Playgroud)
我应该如何在EF 6代码中首先映射这个?
public class MyTable
{
[Key]
public string SomeId { get; set; }
[Key]
public int OtherId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我看过一些例子,你必须为每一列设置顺序,是否需要?
这个地方有官方文件吗?
程序包管理器控制台中的Update-Database失败.我使用了Entity Framework 6.x和代码优先方法.错误是
"数据库中已经有一个名为'AboutUs'的对象."
我怎么解决这个问题?
internal sealed class Configuration
: DbMigrationsConfiguration<Jahan.Blog.Web.Mvc.Models.JahanBlogDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = false;
}
protected override void Seed(Jahan.Blog.Web.Mvc.Models.JahanBlogDbContext context)
{
}
}
Run Code Online (Sandbox Code Playgroud)
我的DbContext是:
public class JahanBlogDbContext : IdentityDbContext<User, Role, int, UserLogin, UserRole, UserClaim>
{
public JahanBlogDbContext()
: base("name=JahanBlogDbConnectionString")
{
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<JahanBlogDbContext>());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Entity<Comment>().HasRequired(t => t.Article).WithMany(t => t.Comments).HasForeignKey(d => d.ArticleId).WillCascadeOnDelete(true);
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<User>().ToTable("User");
modelBuilder.Entity<Role>().ToTable("Role");
modelBuilder.Entity<UserRole>().ToTable("UserRole");
modelBuilder.Entity<UserLogin>().ToTable("UserLogin");
modelBuilder.Entity<UserClaim>().ToTable("UserClaim");
}
public virtual DbSet<Article> Articles { get; set; }
public …Run Code Online (Sandbox Code Playgroud) database entity-framework ef-code-first ef-migrations entity-framework-6
这是我的代码:
var banner = context.Banners.ToListAsync()
var newsGroup = context.NewsGroups.ToListAsync()
await Task.WhenAll(banner, newsGroup);
Run Code Online (Sandbox Code Playgroud)
但是当我从控制器调用该函数时.它显示错误
在先前的异步操作完成之前,在该上下文上开始第二操作.使用'await'确保在此上下文上调用另一个方法之前已完成任何异步操作.任何实例成员都不保证是线程安全的.
请帮我解决这个问题.
c# ×6
asynchronous ×1
database ×1
localdb ×1
mstest ×1
sql-server ×1
teamcity-7.1 ×1
unit-testing ×1