Tag: entity framework 6

“代码优先从数据库”模板不显示在Visual Studio实体数据模型向导中

根据本文中的 Microsft,当在步骤3中的“ADO.NET实体数据模型”下向项目添加新项目时,应该看到“Code First From Database”的选项。 我只看到以下内容 我已经使用nuget安装了EF 6.1,我正在使用Visual Studio 2012 Ultimate ..我错过了什么?

如何连接到Visual Studio服务器资源pipe理器中的LocalDB?

我不能相信,经过一个小时的search,我找不到一个工作的解决scheme。 我正在阅读关于Entity Framework 6.0的这篇文章 ,它给出了Code First的简单介绍。 我创build了该项目,并安装了最新的EF Nuget包以供项目编译。 我还证实,我安装了随Visual Studio 2013一起提供的Microsoft SQL Server 2012 Express LocalDB。我没有在本地计算机上安装任何其他SQL实例。 程序运行并将条目添加到数据库并在控制台中输出。 但是当文章说“检查你的localdb”它不说如何! 我没有看到在项目文件夹下创build的任何“.mdf”或“.ldf”文件。 我想尽一切办法将Visual Studio的服务器资源pipe理器连接到LocalDB。 向导无法find(localdb)或无法在服务器资源pipe理器中find任何提供程序来接受连接string,如(localdb)\v11.0;Integrated Security=true; 我见过这个在StackOverflow中问几个地方,但没有答案工程或标记为答案。 请帮忙,这不一定是这个沮丧! 将Visual Studio Server Explorer连接到LocalDB的步骤是什么?

Entity Framework 6 GUID作为主键:不能将NULL值插入到列'Id',表'FileStore'; 列不允许空值

我有一个主键“Id”的实体,它是Guid: public class FileStore { public Guid Id { get; set; } public string Name { get; set; } public string Path { get; set; } } 还有一些configuration: protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<FileStore>().Property(x => x.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); base.OnModelCreating(modelBuilder); } 当我尝试插入logging时,出现以下错误: 无法将值NULL插入到'Id'列'FileStore'列中; 列不允许空值。 INSERT失败。\ r \ n声明已被终止。 我不想手动生成Guid。 我只想插入一个logging,并获得由SQL Server生成的Id 。 如果我设置.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity) , Id列不是SQL Server中的Identity列。 我如何configurationentity […]

dynamicMySQL数据库连接entity framework6

我希望将dynamic连接string传递给entity framework上下文。 我有超过150模式是相同的(每个帐户一个),我想select连接如下: ApplicationDbContext db = new ApplicationDbContext("dbName"); 从理论上讲,这将是相当容易的,因为我可以创build一个connectionString并将其作为构造函数的parameter passing,例如: public ApplicationDbContext(string dbName) : base(GetConnectionString(dbName)) { } public static string GetConnectionString(string dbName) { // The connectionString passed is something like: // Server=localhost;Database={0};Uid=username;Pwd=password var connString = ConfigurationManager .ConnectionStrings["MyDatabase"] .ConnectionString .ToString(); return String.Format(connString, dbName); } 当我只传递连接string名称时,我可以连接成功,但不能当我如下dynamic生成它。 我现在意识到,这是因为web.config中的连接string中有providerName="MySql.Data.MySqlClient"属性。 当我将实际连接stringdynamic传递给连接时,它假定它需要连接到SQL Server而不是MySQL,并且由于连接string无效而失败。 问题是,如果我dynamic创build它,我如何将提供程序名称传递给连接string?

entity framework6与SQLite 3代码优先 – 不会创build表

使用NuGet的最新版本的EF6和SQLite。 我终于得到了app.config文件后,在Stackoverflow上的一些有用的职位。 现在的问题是,虽然数据库是没有创build表。 我的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> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <entityFramework> <providers> <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> </providers> </entityFramework> <system.data> <DbProviderFactories> <remove invariant="System.Data.SQLite" /> <add name="SQLite Data Provider" invariant="System.Data.SQLite" […]

在Microsoft Visual Studio 2013的WinForms中为MySql(C#)启用entity framework6

昨天我知道entity framework是除了使用数据集或数据读取器之外访问数据库的另一种方法,然后我试图让我的MySql数据库服务器在MVS 2013中使用entity framework6。 我用.Net FrameWork 4.5.1打开一个WinForms。 (所以我只有App.config,但没有在项目中的应用程序/networkingconfiguration)我安装了mysql-installer-community-5.7.3.0-m13.msi和 通过安装EntityFramework包 工具菜单 – >库包pipe理器 – >pipe理解决scheme的NuGet包… – >联机 – >(search)EntityFramework(小心这个包的版本,它应该是版本6.0.2,如果没有,然后单击更新 – > EntityFramework更新) 当我试图通过添加ADO.NET实体数据模型 右键点击Project – > Add – > New Item – > ADO.NET Entity Data Model – > Generate from Database – > New Connection – > Data sources: – > Change …-> MySQL Database […]

用stream畅的API设置唯一的约束?

我试图用Code First构build一个EF实体,而使用stream利的API来构build一个EntityTypeConfiguration 。 创build主键很容易,但是使用唯一约束不是那么容易。 我看到的旧postbuild议为此执行本地SQL命令,但这似乎是失败的目的。 这是可能的与EF6?

EF代码 – 第一对一关系:多重性在关系中的angular色*中是无效的

我试图做到以下几点: public class class1() { public int Id {get;set;} [ForeignKey("Class2")] public int Class2Id {get;set;} public virtual Class2 Class2 {get;set;} } public class class2() { public int Id {get;set;} [Required] public virtual int Class1Id {get;set;} [Required] [ForeignKey("Class1Id")] public Class1 Class1 {get;set;} } 但是,每次我尝试迁移我的数据库时,我得到以下错误: Class1_Class2_Target :: Multiplicity在关系“Class2_Class1”中的angular色“Class2_Class1_Target”中无效。 由于“依赖angular色”属性不是关键属性,所以“依赖angular色”的多重性的上界必须是“*”。 这里可能是什么问题?

entity framework提供程序types无法加载?

我想在我的机器上安装的TeamCity上运行我的testing。 System.InvalidOperationException : “ System.Data.SqlClient ”ADO.NET提供程序的entity framework提供程序types“ System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer , Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'不能加载。 确保提供者程序集可用于正在运行的应用程序。 有关更多信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882 。 在我的任何项目中都没有提及System.Data.Entity ,就像在codeplex上build议升级到EF6一样。 所以,我不知道为什么我得到这个exception。 当我从VS运行testing时,我没有得到任何这样的exception。 我确实尝试将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" […]