entity-framework-6

Same application, different databases: Entity framework 6.X + MySQL + SQL Server

橙三吉。 提交于 2019-11-30 06:56:29
Yesterday I did migration (EF 5.0 => EF 6.0) of web application that uses entity framework to reach MySql and SQL Server databases (particular DbContext to particular databases, NOT any DbContext to any type of database). Compile time things were done without any issues, run-time faced me with exception: The default DbConfiguration instance was used by the Entity Framework before the 'MySqlEFConfiguration' type was discovered. The [DbConfigurationType(typeof(MySqlEFConfiguration))] attribute on the context appears to have been ignored at run time because the context is in an external assembly(

Error: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'

假装没事ソ 提交于 2019-11-30 05:57:02
问题 I recently upgraded/updated Entity Framework in an old project from version 4 or 5 to version 6. Now I get this exception: An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code Additional information: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go

How to use SqlServer.Types / spatial types within ASP.NET Core 1.0 application

偶尔善良 提交于 2019-11-30 03:55:01
One of our class libraries uses the Microsoft spatial types like DbGeography. When running our application on a clean machine without older versions of SQL Server and Visual Studio, we get this exception: Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found. The solution is apparently to install this nuget package: Install-Package Microsoft.SqlServer.Types After installing, the nuget package gives instructions on how to reference the DLLs from each project type: To deploy an application that

How to add entity framework 6 provider in code?

六月ゝ 毕业季﹏ 提交于 2019-11-30 03:17:35
问题 I use Entity Framework 6 in a C# application and it works perfectly. When creating the Model, the app.config is generated with all the necessary configuration. Now I don't like having stuff in the app.config, so I use the connection string builder. I succeeded in removing everything out of the app.config file except of this: <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <providers> <provider invariantName="System

Entity Framework include filter child collection

泪湿孤枕 提交于 2019-11-30 03:02:55
问题 I have some difficulty to add some filter condition for included items in my LINQ query. My query is like var item = _Context.Order.Include("Inner") .Include("Inner.first") .Include("Inner.second") .Where(x => ( !(x.IsDeleted) && (x.IsActive) && (x.itemid == id))).FirstOrDefault(); In the above code "Inner" is another list of item. Now i need to filter inner items. I only need inner item with filter condition inner.isDeleted = true. Query should return a class like, public class Order {

How can I manage EF 6 migrations in visual studio 2015?

爱⌒轻易说出口 提交于 2019-11-30 02:50:58
问题 I started a new MVC project with EntityFramework -Version 6.1.2 using Visual Studio 2013 latest update. I made a couple of migrations and updated the database. After this I checked out the project on another computer and opened with Visual Studio 2015 CTP 6. If I go in the package manager console and try to run any migration commands, they're not recognized: add-migrations : The term 'add-migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. Check

entity framework execute SQL before migrations

安稳与你 提交于 2019-11-30 02:06:26
问题 I am working on an existing project that uses Entity-Framework 6 with code-first. I have a need to run some SQL before the migrations run. I have a DbMigrationsConfiguration class with a seed method, but seed runs after the migrations. I think it will work if I run my SQL in the constructor but I can't get a reference to the context. Does anyone know how to do this? 回答1: You could use the 'Sql' method within the desired migration class. public partial class OneOfYourMigrations : DbMigration {

Using TransactionScope with Entity Framework 6

五迷三道 提交于 2019-11-30 01:47:27
What I can't understand is if its possible to make changes to the context and get the changes in the same transaction before its commited. This is what I´m looking for: using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (var context = new DbContext()) { //first I want to update an item in the context, not to the db Item thisItem = context.Items.First(); thisItem.Name = "Update name"; context.SaveChanges(); //Save change to this context //then I want to do a query on the updated item on the current context, not against the db Item thisUpdatedItem = context.Items

Scaffolding controllers with repositories in Mvc5, EF6, VisualStudio 2013

对着背影说爱祢 提交于 2019-11-30 01:10:54
问题 In vs2012 I used to use Steve Sanderson's mvcScaffolding Package with this package I could scaffold Action Methods with unit tests and controllers with repositories and dependency injection. My question is simple. Is there a way to do so in vs2013? When I install the package in vs2013 I get the following errors: Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE At C:\dev\WebApplication2\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:50 char:9 + Set-DefaultScaffolder -Name

Using SqlQuery to get IQueryable

邮差的信 提交于 2019-11-30 00:48:27
问题 Is there something that can return IQueryable for a dynamic sql query in Entity Framework 6? This is what I am using now but it is pulling all the records (as expected). DbContext.Database.SqlQuery<T>("SELECT * FROM dbo.SomeDynamicView") Problem is that SqlQuery returns DbRawSqlQuery which is IEnumerable . dbo.SomeDynamicView is a database view created at runtime. 回答1: No, you can't get a IQueryable from SqlQuery * , this is because what IQueryable is doing is building a SQL string