entity-framework-6.1

Entity Framework creates empty migration but insists that my model is different

主宰稳场 提交于 2019-12-30 08:36:23
问题 Today is a sad day. First thing today I saw EF exception saying that " The model backing the 'DomainContext' context has changed since the database was created. ". It is close to midnight and I still see this error. This is the end of my career -( I'm pretty sure nothing has changed in the model, yet the error appeared. I have tried creating a new migration, it came out empty: public void Up() { } public void Down() { } Applying this migration did not do any good - the error persisted. I've

Entity Framework: Checking all relationships of an entity fails in 6.1.1

女生的网名这么多〃 提交于 2019-12-25 03:48:24
问题 I've had success using this code to check all relationships when using Entity Framework ver. 5. (from yildizm85, Entity Framework: Check all relationships of an entity for foreign key use) public bool IsUnitNameInRelationship(UnitName unitName) { bool hasRelation = false; var allRelatedEnds = ((IEntityWithRelationships)unitName).RelationshipManager.GetAllRelatedEnds(); foreach (var relatedEnd in allRelatedEnds) { if (relatedEnd.GetEnumerator().MoveNext()) { hasRelation = true; break; } }

update-database fires: “There is already an object named 'Adresses' in the database”.

我是研究僧i 提交于 2019-12-23 05:44:08
问题 I can't get my seed method to run on an alredy existing database. The database was a result of multiple migrations where we migrated our own created database, "Whitelabel", with the ASP.NET MVC5 Identity database (that we call "IdentityDb"). Here's an overview of the database tables: Since this is made code-first, I used the package manager console to update the database with this command: PM> update-database -ConfigurationTypeName DAL.DataContexts.WhitelabelMigrations.Configuration And it

User.IsInRole failing after migrating SimpleMembership database to Identity 2

不想你离开。 提交于 2019-12-22 13:31:39
问题 I successfully updated my application from MVC4-EF5 to MVC5-EF6. I then migrated my database from Simplemebership to Identity 2.0. I can login but User.IsInRole always returns false. All the proper tables AspNetUsers, AspNetRoles, AspNetUserRoles, AspNetLogins and AspNetClaims have been created, the spelling and type of all columns are correct and they have been populated with the data from the SimpleMembership tables (which have been deleted). I have a user "MyUser" which is Id = 2 in the

Generating a SQL view from EF 6.1 code first

ぃ、小莉子 提交于 2019-12-21 13:43:30
问题 I just changed my application from Database first to code first! What a great improvement in deploying!. But now i have the following problem. I generated my Code-first model from my database, but after recreating the database from the generated code, my views from my database are generated like tables! How do I generate my views from code first? and/or map them to my entities if I need to generate them manually? EDIT. Luke McGregor's post certainly brought me close. Yes it generates the

store only date in database not time portion C#

为君一笑 提交于 2019-12-21 07:25:42
问题 I have a test class and an ExecutionDate property which stores only date but when we use [DataType(DataType.Date)] that also stores the time portion in database but I want only date portion. public class Test { [Key] public int Id { get; set; } [DataType(DataType.Date)] public DateTime ExecutionDate { get; set; } } Is any way to store only date on time portion in db using Entity Framework? Please help me.... I have added snapshot when use [DataType(DataType.Date)] that stores time portion 00

Does ignoring a base type in Entity Framework Code First also ignore subclasses?

你离开我真会死。 提交于 2019-12-20 05:34:08
问题 I'm attempting to simulate a scenario in which I am inheriting from concrete base classes in a 3rd party library, then mapping my own classes using Entity Framework Code First. I would really prefer for my classes to have the same simple name as the base classes. I obviously can't change the class names of the base classes, nor can I change the base class to abstract. As expected, I get the following error: The type 'EfInheritanceTest.Models.Order' and the type 'EfInheritanceTest.Models.Base

MVC model binding to edit a list not working

不羁的心 提交于 2019-12-13 00:45:27
问题 I can't figure out why this won't work. Everything I've read (both here and across the web) says this is how to bind to a list for editing but I'm not having any success. I have two problems: The HTML form elements emitted by the view are not being indexed (each one is named "Qty" and "BoxID" instead of "[0].Qty" and "[0].BoxID"). Everything I've read on this subjuct says the HTML.EditorFor and HiddenFor helpers should pick this up automatically. Even when I manually change the view to spit

SetExecutionStrategy to SqlAzureExecutionStrategy with DbMigrationsConfiguration?

谁都会走 提交于 2019-12-12 09:34:13
问题 I saw a post today about implementing SqlAzureExecutionStrategy: http://romiller.com/tag/sqlazureexecutionstrategy/ However, all examples I can find of this use a Configuration that inherits from DbConfiguration. My project is using EF6 Code First Migrations, and the Configuration it created inherits from DbMigrationsConfiguration. This class doesn't contain a definition for SetExecutionStrategy, and I can find no examples that actually combine SqlAzureExecutionStrategy (or any

EntityFramework Stored Proc Function Import is it possible to read async?

安稳与你 提交于 2019-12-12 08:43:57
问题 I'm using EF 6.1.1 and Database First. When I import a stored proc into the edmx and generate the DBContext it looks like this: return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<TestSP_Result>("TestSP", params[]...) That returns an ObjectResult< T >, which implements IDbAsyncEnumerable< T > so I'm doing this to read the data async: IDbAsyncEnumerable<T> enumerable = objectResult as IDbAsyncEnumerable<T>; IDbAsyncEnumerator<T> enumerator = enumerable.GetAsyncEnumerator(); List