entity-framework-5

Handling enum changes in Entity Framework 5

拟墨画扇 提交于 2019-12-08 19:38:18
问题 In this question, I discovered that enum changes are not handled by Entity Framework migrations. In fact, enum changes don't even result in a model changed error, so you can change enums at will with no controls. Enum changes that result in different int values, such as order changes or removals, can effectively render the database data invalid, since the meaning of the stored integer is now wrong. In order for Migrations to work, you have to manually execute custom SQL that changes the

How to use Include() after OfType()?

点点圈 提交于 2019-12-08 17:41:49
问题 I am trying to eager load properties of a derived class in an Entity Framework model. I read all over the place that I have to first filter the set with OfType() before including properties with Include(): var persons = Context.Persons .OfType<Employee>() .Include("Compensation") I don't know how to get that Include() to work though because in my case, Persons is a DbSet, OfType() returns an IQueryable and IQueryable does not define an Include() method. 回答1: Place this: using System.Data

How to add the “Provider Name” in Connection String to the Context file?

血红的双手。 提交于 2019-12-08 16:12:10
问题 I am Using Entity Framework 5 Code-first approch. Here is my Context file : using IMS.Domain.Inventory; using IMS.Domain.Security; using IMS.Domain.StoredProcedures; using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Data.Objects; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IMS.Domain.DBContext { public class IMSDBContext : DbContext { public DbSet<ModuleAccounting> ModuleAccountings

Entity Framework and SQL Server 2012 Paging

做~自己de王妃 提交于 2019-12-08 16:05:03
问题 SQL Server 2012 introduces a more efficient mechanism for paging using FETCH and OFFSET which could have a big impact on performance of apps which use a lot of paging. Does Entity Framework 5 support this? So if Im using EF to page using Take + Skip will the LINQ queries be translated into the new 2012 TSQL if EF is targeting SQL Server 2012? 回答1: EF 5 doesn't support this feature - actually I think none of SQL Serve 2012 features is available in EF. You can vote for this feature on Data

Filtering inner collection with Entity Framework 5 and Repository pattern and Unit of Work

青春壹個敷衍的年華 提交于 2019-12-08 13:35:32
问题 I'm using the Repository and Unit Of Work Pattern with Entity Framework 5 I want to get all the "Agencies" with its "Cars" but only those Cars that have an id in the list sent by parameter and that belongs to the state sent by parameter. For example public IEnumerable<Agency> GetList(int stateId, string idCarList) var ids = idTiposTarjetasList.Split(','); var intIds = ids.Select(int.Parse); Then I have Uow.Agencies.GetAll() and Uow.Agencies.GetAllIncluding(a => a.Cars) which retrieves an

Add new table to EF

我们两清 提交于 2019-12-08 13:03:29
I have a project in MVC4 (VS 2012) with Entity Framework. I have created a model by connecting to SQL Server 2008. Works great. Now I want to add one or more tables to the model. Here's what I did: opened the .edmx file. Right clicked and selected Update model from the database. Under the Add tab, it shows Tables, Views and Stored Procedure. But none of them is selectable. Am I missing something here? Murali, if I understood well, the problem is that you didn't make changes to the database since you've created the model. If this statement is correct, take a look at this: Add tables starting

Connection string to remote DB when using EntityFramework

巧了我就是萌 提交于 2019-12-08 11:52:18
问题 I have an ASP.NET MVC application, and I'm making use of EntityFramework 5.0. I've also installed a 'CodeFirstMembershipProvider' Nuget package, which provided some code for ASP.NET membership - and I believe also made changes to my web.config. Basically, my problem is that my application works fine on a local SQL Server instance, but when I specify a remote DB using this connection string: <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=******

Entity Framework Code First check Database exist

▼魔方 西西 提交于 2019-12-08 09:31:35
问题 In Entity Framework Code first i want to check database is exist before create Database. In code first when i call Entities dc = new Entities() then it goes to OnModelCreating and generate Database. How can i check if the Database exists in Entity framework Code first? 回答1: You can do: using(var dbContext = new MyContext()) { if (!dbContext.Database.Exists()) dbContext.Database.Create(); } Edit: Following the colegue sugestion, the meaning of this code is very simple: Supose your context

Using a entity framework 5 project dll with Web project using EF6

流过昼夜 提交于 2019-12-08 08:56:13
问题 I have a logging solution that uses EF5 which I am referencing in a new a new web application that uses EF 6. I am getting the following error when consuming the anything from that logging dll: Method not found: 'System.Data.Objects.ObjectContext System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()' I know why I am getting the error, it's because namespaces have changed from EF5 to EF6, but is there a way I can have the two co-exist without having to change my EF5

Extracting a complex type from entry.CurrentValues

◇◆丶佛笑我妖孽 提交于 2019-12-08 07:55:03
问题 Some of my domain classes contain a complex type for a street address. I am capturing a log of my changes, and want to be able to reconstruct the address object from the ObjectStateEntry.CurrentValues My code is detailed here And I want to extract the address from CurrentValues as the answer suggests. I can see the address in the _userObject property in the debugger, but i don't know how to extract it. I have tried var obj = entry.CurrentValues[ordinal]; var rec = (DbDataRecord)obj; what