entity-framework-6

Conventions for joins in Entity Framework 6.1.0 Code First

老子叫甜甜 提交于 2019-12-01 10:56:49
问题 I believe my question is simple (not sure if the answer is as well): Does anybody know how to force Entity Framework to use "INNER JOIN" as default convention, instead of "LEFT OUTER JOIN"? 回答1: If you want to enforce inner or outer joins explicitly you can always use the Join or GroupJoin methods, respectively. (Or the comprehensive equivalents join and join ... into ). But, generally speaking, in LINQ statements you should avoid using explicit join statements. Use navigation properties

ObjectContext.GetObjectType(e.GetType()) not returning the entity type of the POCO entity

本秂侑毒 提交于 2019-12-01 10:39:16
The ObjectContext.GetObjectType Method should return "the entity type of the POCO entity associated with a proxy object of a specified type" So how come in my code it just returns the proxy? I am using entity framework 6 release candidate //Soft delete var e = Context.Set<T>().Find(id); e.IsDeleted = true; InsertOrUpdate(e); Type t = System.Data.Objects.ObjectContext.GetObjectType(e.GetType()); string name = t.Name; //Property_6C887DE7274181E6E99D6FCF2C21BDD59E226F99B0064F59954E70062C135331 //Surely I shouldn't have to use Substring here? name = name.Substring(0, name.IndexOf("_"))

Entity Framework profiler - ASP.NET MVC4 with EF 6 -Unable to determine the provider name

梦想与她 提交于 2019-12-01 10:29:50
I've been using EF 6 in my ASP.NET MVC4 project for a while now without any issues. The problem comes in when I add Entity Framework Profiler to the project, then suddenly I get the following error: "Unable to determine the provider name for provider factory of type 'System.Data.SqlClient.SqlClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config." I've tried a couple of suggestions including an issue where the "EntityFramework.SqlServer.dll" was not present in the bin folder. Stack trace: System.Data.Entity.Config.DefaultInvariantNameResolver

Getting DbContext from implementation of IDbCommandInterceptor

谁说胖子不能爱 提交于 2019-12-01 09:28:36
I am using an IDbCommandInterceptor implementation: public class MyInterceptor : IDbCommandInterceptor { public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { var context = interceptionContext.DbContexts.FirstOrDefault(); } public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { } public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { } public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int>

Emit DbContext.OnModelCreating on every context creation

孤者浪人 提交于 2019-12-01 09:16:35
I use entity framework code first to work with my database. I have several tables with different names but same structure, and this tables dynamically appears in database. How could I map EntityFramework to one of that tables at run-time and use data from just like I work this over entities of DbContext? What I've done to make it work: For example, my class what describes structure of dynamically created table is SetElement . Here is my context: public class DataContext : DbContext { public DataContext() : base("RepositoryConnectionString") { } string setElementsTableId; // the name of table

Adding Many to Many relationship from ApplicationUser to custom entity

风格不统一 提交于 2019-12-01 09:09:45
问题 I'm trying to setup a many to many relationship in EF 6.1 from the User entity (ApplicationUser) in ASP.NET Identity to a custom entity (Group). I'm using Code First and Migrations with the stock standard MVC sample app with ASP.Net Identity. Running Update-Database seems to work nicely as I end up with all the AspNet* tables plus my entity and a linking table: Groups GroupAspNetUsers My ApplicationUser declaration has a collection of Group, and likewise my Group has a collection of

Entity Framework profiler - ASP.NET MVC4 with EF 6 -Unable to determine the provider name

点点圈 提交于 2019-12-01 08:38:51
问题 I've been using EF 6 in my ASP.NET MVC4 project for a while now without any issues. The problem comes in when I add Entity Framework Profiler to the project, then suddenly I get the following error: "Unable to determine the provider name for provider factory of type 'System.Data.SqlClient.SqlClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config." I've tried a couple of suggestions including an issue where the "EntityFramework.SqlServer.dll"

Nullable fields are created when customizing IdentityUser class in asp.net Identity

天涯浪子 提交于 2019-12-01 08:36:47
I am trying to customize IdentityUser class in asp.net identity. public class ApplicationUser : IdentityUser { public ApplicationUser() { IsBlocked = false; } public bool IsBlocked { get; set; } } The problem is: when using code first migrations, the additional field is created nullable. The same if I drop database and recreate it. CREATE TABLE [dbo].[AspNetUsers] ( [Id] NVARCHAR (128) NOT NULL, [UserName] NVARCHAR (MAX) NULL, [PasswordHash] NVARCHAR (MAX) NULL, [SecurityStamp] NVARCHAR (MAX) NULL, [IsConfirmed] BIT NOT NULL, [IsBlocked] BIT NULL, [Discriminator] NVARCHAR (128) NOT NULL,

EntityFramework 6 Code-based configuration of connection string for database-first

大兔子大兔子 提交于 2019-12-01 08:14:46
问题 I'm attempting to make an existing application work without an app.config (it is required due to a very specific environment). Problem is that it's heavily relying on EntityFramework 6 to work with an SQL-Server. I'm trying to use a code-based configuration, but I can't figure out how to provide a correct connection string through my configuration class. I made a configuration class: public class MyConfiguration : DbConfiguration { public MyConfiguration() { SetDefaultConnectionFactory(new

Database is not getting created at first time

Deadly 提交于 2019-12-01 07:55:35
问题 How to re-create the database using EF6? I have tried both of following post but, i don't know why its not working and getting same error. How do I generate an EF6 database with migrations enabled, without using update-database? Migrations is enabled for context ''but the database does not exist or contains no mapped tables I have already published my sample on the web server. I am using Sql Server 2012 Express DBMS. When i have created my application and published it on web server it was