entity-framework-6

How to re-create initial migration on the same .cs file

有些话、适合烂在心里 提交于 2019-12-09 16:22:05
问题 As common in EF Code First I've generated an "Initial Create" migration file where is located an outdated model of my db (I'm developing the app so the model is still changing). Now I have a "new model" defined in my code and instead of creating a new migration for that I just want to update the already existing file, because it still is the initial create migration. I've tried using this without any luck Update-database -targetmigration $initialcreate It returns Unable to update database to

Entity framework manually deleted tables cant be generated from EF migration

谁说胖子不能爱 提交于 2019-12-09 16:06:17
问题 I have created migration and created the database and the tables . For example the tables are A B C D E . Now again I have changed some part of code and ran update-database command . Everything went smooth and nice and the tables showed the columns . Now accidentally I manually deleted one two tables D and E . Now when I try to run the migration with update-database . It runs properly but doesn't create the tables which I deleted manually . I tried to delete the existing migration and re-run

“Update-Database” command fails with TimeOut exception

巧了我就是萌 提交于 2019-12-09 14:14:21
问题 I'm using EF migrations and have a table with a lot of data. I need to change MaxLength of a concrete column (it hadn't length constraints). ALTER TABLE MyDb ALTER COLUMN [MyColumn] [nvarchar](2) NULL And this command fails with TimeOut exception. Tried to setup CommandTimeout i nDbContext constructor without any luck. Is there any way to disable or setup timeout for Package Manager Console EF commands? 回答1: Alternatively script out the change by using Update-Database -script You can then

Could not connect to MySQL through EF6 in Visual Studio 2013

老子叫甜甜 提交于 2019-12-09 10:48:03
问题 I am trying to connect to MYSQL Database using EF6 in visual studio , later i was using SQL and it worked fine afterwards i shifted to Mysql then i install such this required components : MySQL for Visual Studio 1.1.1 MySQL Connector/Net 6.8. The error says : Your project references the latest version of Entity Framework; however, an Entity Framework database provider compatible with this version could not be found for you data connection. Exit this wizard, install a compatible provider, and

Return an object along with a 409 Conflict error in a Web API 2 POST call backed by Entity Framework?

删除回忆录丶 提交于 2019-12-09 08:05:18
问题 I have a C# Entity Framework Web API 2 controller . Currently when an attempt is made via the POST method to create an object with the same text for the main text field, I return a 409 Conflict error as an StatusCode result to indicate the addition is considered a duplicate. What I'd like to do is return the server side object that triggered the duplicate error too. So I need something akin to the Ok() method but a variant that returns a 409 Conflict error as the HTTP status code instead of

FindAsync with non-primary key value

邮差的信 提交于 2019-12-09 07:53:38
问题 public class Foo { public int Id { get; set; } public int UserId { get; set; } } This appears to be the way to do this asynchronously: DatabaseContext db = new DatabaseContext(); Foo foo = await db.Foos.FindAsync(fooid); How does one asynchronously get all of the Foos for a specific user based on UserId's value? 回答1: Assuming you are using Entity Framework 6.0 (prerelease): var userId = ...; var foos = await db.Foos.Where(x => x.UserId == userId).ToListAsync(); 来源: https://stackoverflow.com

Entity Framework's Entity Data Wizard Crashes When Connecting to MySQL Database

二次信任 提交于 2019-12-09 07:45:01
问题 I am attempting to create an Entity Data Model using the wizard to reverse engineer an existing MySQL database. I get to the Choose Your Data Connection page of the wizard, select an existing MySQL connection and click Next, and the wizard crashes. Specifically, the dialog box just disappears without an error message or any trace. Every single time. Restarting VS or Windows does nothing. I can connect to the database using Server Explorer and the same connection without problem, so I'm fairly

DbSet<entity>.Load() function missing in EF 6.0

佐手、 提交于 2019-12-09 07:36:28
问题 I am trying to access the DbSet<EntityClass>.Load() function to load the entities. This function no longer exists in EF 6.0; upon certain investigation I found that it is a part of the extension methods defined in the EF extension library. I get the reference NuGet Packages for EF 6.0 extended library but seems like it's no longer supported. I tried to do an alternative of that function by calling .ToList() , but this method upon processing returns me an inner exception: ({"The column name is

Modify the expression tree of IQueryable.Include() to add condition to the join

六眼飞鱼酱① 提交于 2019-12-09 07:16:13
问题 Basically, I would like to implement a repository that filters all the soft deleted records even through navigation properties. So I have a base entity, something like that: public abstract class Entity { public int Id { get; set; } public bool IsDeleted { get; set; } ... } And a repository: public class BaseStore<TEntity> : IStore<TEntity> where TEntity : Entity { protected readonly ApplicationDbContext db; public IQueryable<TEntity> GetAll() { return db.Set<TEntity>().Where(e => !e

Is there an EF6 DbContext Generator for C# which uses Fluent API?

落爺英雄遲暮 提交于 2019-12-09 07:12:53
问题 I know that the EF6 VS Tools for Visual Studio 2012 come with a T4 template to generate DbContext classes which work with EF6. But I want to have a generator which uses fluent API. The older version I used with EF4 and EF5 don't work with EF6 and the author no longer works on them to make them EF6 compatible. Is anyone else working on a generator which uses Fluent API which works with EF6? 回答1: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d If you have a