entity-framework-5

Filter all navigation properties before they are loaded (lazy or eager) into memory

≡放荡痞女 提交于 2019-12-03 02:31:07
问题 For future visitors: for EF6 you are probably better off using filters, for example via this project: https://github.com/jbogard/EntityFramework.Filters In the application we're building we apply the "soft delete" pattern where every class has a 'Deleted' bool. In practice, every class simply inherits from this base class: public abstract class Entity { public virtual int Id { get; set; } public virtual bool Deleted { get; set; } } To give a brief example, suppose I have the classes GymMember

How to upgrade from Entity Framework 4.3 to EF 5

风流意气都作罢 提交于 2019-12-03 02:00:40
Currently we are working on the EF 4.3 . We would like to upgrade it to EF5. I have google the upgrade process steps, but I did not get any result. Please help me..! Thanks.. :) Here are two links for you of content I've created on EF4.3 to EF5: article: Moving Existing Projects to EF 5 http://msdn.microsoft.com/en-us/magazine/jj618295.aspx video: Entity Framework 5 Enums and Moving Solution from EF 4.3 http://thedatafarm.com/blog/data-access/video-entity-framework-5-enums-and-moving-solution-from-ef-4-3/ hth julie 来源: https://stackoverflow.com/questions/12652920/how-to-upgrade-from-entity

How to rename a database column in Entity Framework 5 Code First migrations without losing data?

戏子无情 提交于 2019-12-03 01:33:53
问题 I got the default ASP.NET MVC 4 template successfully running with EF 5.0 Code First Migrations. However, when I update a model property name, the corresponding table column data is dropped by EF 5.0. Is it somehow possible to rename the table column without dropping data in an automated way? 回答1: Manually edit the Up and Down methods of the migration to use the RenameColumn method to replace the AddColumn and DropColumn that it automatically generates for you. 回答2: As already said, replace

Using an SQL View from an Entity Framework Code First version 5

这一生的挚爱 提交于 2019-12-03 01:29:57
I am developing a contact log in a website using VS 2010, MVC3 and EF 5 - the entities are created using code first. The data is stored in an SQL Server 2008 R2 set of databases. I want to display a summary of the contact log and have created a view. CREATE VIEW dbo.ContactLogSummaries AS SELECT CLE.ContactLogEntryID, CLE.CaseID, 'Test' AS ContactName, EU.UserName As OfficeUser, CLE.DateAndTimeOfContact, CLC.Category, CLE.ContactDetails FROM ContactLogEntries AS CLE JOIN ContactLogCategories AS CLC ON CLE.ContactLogCategoryID = CLC.ContactLogCategoryID JOIN Control.dbo.EndUsers AS EU ON CLE

Tinyint(byte),SmallInt(Int16) not compatible with Enum in EF5

喜你入骨 提交于 2019-12-03 01:18:15
Using Database first design and having tinyint (or smallint) column: [MyEnumColumn] [tinyint] NOT NULL I mapped this column to Enum Type in EDM with External Type: NSpace.MyEnumType Name:MyEnumType UnderlyingType:Byte Where NSpace.MyEnumType is defined like this: public enum MyEnumType { One, Two, Three, All } Only to get this error when trying to load entity from context: Schema specified is not valid. Errors: No corresponding object layer type could be found for the conceptual type 'EntityDataModel.MyEnumType'. The following information may be useful in resolving the previous error: The

Adding and updating entities with Entity Framework

本小妞迷上赌 提交于 2019-12-03 00:04:17
In my last project I have used Entity Framework 5 Code First. I completed my project but had a lot of pain during the development process. I tried to explain my pain below: I had several data classes in my data access logic layer like Product, ProductCategory, Order, Company, Manufacturer etc... Each class has some references to some other classes. For example, a Product instance has a ProductCategory property. Inside Add and Update methods of my Data Access Object classes I set the states of each property (other than the primitive types) to Unchanged or Modified in the context. Below is some

EF 5, update object gives “A referential integrity constraint violation occurred”

血红的双手。 提交于 2019-12-02 21:03:51
In my model I've got a bunch of domain objects. Now I'm having a problem when trying to update a User-object. The User has a foreignkey relation to the Role object. When I update the User-object without changeing the foreignkey value (FkRoleId) it all works fine. But when I change the role for the current user I want to update I get the error: A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects in the relationship. Here's how I update my user-object: public void Update(User

Entity Framework code first update-database fails on CREATE DATABASE

北城以北 提交于 2019-12-02 20:44:39
This post has been noted So has this one On my dev machine I am trying to recreate my database using update-database from package manager console. I believe I have followed the instructions in the posts cited above. I get this error message: A file activation error occurred. The physical file name '\WRDatabase.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation. CREATE DATABASE failed. Some file names listed could not be created. Check related errors. The command I am running is: update-database -ConfigurationTypeName WRConfiguration -ConnectionStringName

Ignore TransactionScope for specific query

安稳与你 提交于 2019-12-02 18:59:14
I'm looking for a way to execute a query while a TransactionScope is alive, and ignore the TransactionScope - basically, I want to execute this particular query no matter what. I'm using EF code-first, and the way the application is designed, a new data context is opened many times throughout a single call, each with its own changes, and all of those are contained within a single TransactionScope, which has Complete() called at the end assuming no failures. Inside of the context we've overridden SaveChanges so that if any exception happens on base.SaveChanges() , we can catch it and log to the

Consolidating EF migrations into new InitialCreate

南楼画角 提交于 2019-12-02 17:51:34
I have been using EF migrations for some time now and have more than 100 migration files in my project. I would like to consolidate these into a single migration before moving forward - ie I want to replace the existing InitialCreate migration with a new version that takes all my subsequent changes into account so I can then delete all the other migration files. I do this very easily if I am not concerned with losing all the data in the DB, but I am. How can I achieve this whilst keeping all data intact and also retaining the ability to recreate the database from scratch (without data) by just