我的WPF / EntityFramework应用程序不能在其他计算机上运行

时间:2015-06-13 23:04:08

标签: c# wpf entity-framework

我创建了一个WPF应用程序,它首先在LocalDb上使用实体框架/代码(我已经在"模型"目录上创建了我的数据库,所有内容似乎都很好。)

它在我的笔记本电脑上工作得很好,我想与我的朋友分享,但它不起作用。我认为我在另一台计算机上有一个SQL错误,但它没有显示它。它只显示了一个Windows应用程序错误......我认为当我尝试加载我的数据库上下文时。

我的数据库上下文:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;

namespace ModernUINavigationApp1.Model
{
    class Supcontext : DbContext 
    {
        public DbSet<InfosConnexion> InfosConnexions { get; set; }
        public DbSet<InfosFichiers> InfosFiles { get; set; }
        public DbSet<Log> Logs { get; set; }
    }
}

我的app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

编辑:

安装了localDb,我可以在每台计算机上构建并运行一个新的实体框架解决方案,并查看服务器资源管理器上的localdb(在visual studio上)。在我的解决方案(我试图共享的那个)和另一台计算机上,我删除了app.config,删除并重新导入实体框架,并在控制台上启用迁移和更新数据库,然后它可以工作,但它& #39;我认为不是正确/更好的解决方案。

临时解决方案,见评论

我找到了解决方案:如果您从其他计算机打开已经存在的带有实体框架(和localdb)的Visual Studio解决方案,则必须通过右键单击解决方案(在解决方案资源管理器上)从此解决方案中删除实体框架在visual studio中,选择数据包管理器,删除实体框架并再次安装(也在数据包管理器中)。 它将使用正确的行配置生成一个新的app.config,它应该可以工作!

0 个答案:

没有答案
相关问题