entity-framework

How to log SQL generated by EF using log4net

时光怂恿深爱的人放手 提交于 2021-02-07 09:19:21
问题 In my web project I'm using EF6 and I'd like to log generated SQL for debugging purpose. I'm also using log4net to handle logs, so I'm looking for a way to integrate them together. What's the correct way to achieve this? 回答1: At the moment I'm using this approach: in my BaseController I have something like this: public class BaseController { protected MyDbContext DataContext { get; set; } protected readonly ILog logger; public BaseController() { DataContext = new MyDbContext(); logger =

How to log SQL generated by EF using log4net

若如初见. 提交于 2021-02-07 09:17:00
问题 In my web project I'm using EF6 and I'd like to log generated SQL for debugging purpose. I'm also using log4net to handle logs, so I'm looking for a way to integrate them together. What's the correct way to achieve this? 回答1: At the moment I'm using this approach: in my BaseController I have something like this: public class BaseController { protected MyDbContext DataContext { get; set; } protected readonly ILog logger; public BaseController() { DataContext = new MyDbContext(); logger =

'EntityState' is an ambiguous reference between 'System.Data.EntityState' and 'System.Data.Entity.EntityState'

一个人想着一个人 提交于 2021-02-07 08:47:34
问题 I'm getting the error 'EntityState' is an ambiguous reference between 'System.Data.EntityState' and 'System.Data.Entity.EntityState' I'm getting this error on my 4 controllers using mvc5 entity framework . The line in question is db.Entry(director).State = EntityState.Modified; Same on each controller just different models. 回答1: Simply provide the fully-qualified EntityState depending on whichone you want: db.Entry(director).State = System.Data.EntityState.Modified; or db.Entry(director)

How to include all underlying navigation properties automatically with entity framework

邮差的信 提交于 2021-02-07 08:26:09
问题 Scenario: I'd like to add an entity to the database that would have navigation properties and that entity has navigation properties.. and so on. Basically the tables in the database are connected with each other - all of them. I use EF4.3 and context/request pattern, so I don't want to enable Lazy loading; it would simply just take too much time to load the entity that I need. So far I have learned there is no other way to do it than to use the include method like this: context.Set<TEntity>()

How to include all underlying navigation properties automatically with entity framework

China☆狼群 提交于 2021-02-07 08:24:05
问题 Scenario: I'd like to add an entity to the database that would have navigation properties and that entity has navigation properties.. and so on. Basically the tables in the database are connected with each other - all of them. I use EF4.3 and context/request pattern, so I don't want to enable Lazy loading; it would simply just take too much time to load the entity that I need. So far I have learned there is no other way to do it than to use the include method like this: context.Set<TEntity>()

How to use “dotnet watch run” with .Net Core 3, Visual Studio 2019 and docker

对着背影说爱祢 提交于 2021-02-07 08:22:54
问题 I'm playing with docker and .NET Core 3 using Visual Studio 2019. I containerize my application by adding the Dockerfile to my project (right click on the project -> Add -> Docker Support) and I was able to launch it, but now I want to use dotnet watch run inside the container. This is the generated Dockerfile: FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build WORKDIR /src COPY [

Entity Framework: Why is a property of type array of objects not persisted to DB?

為{幸葍}努か 提交于 2021-02-07 06:59:10
问题 I have two entities where one has a one to many relationship to the other. Example: public class Question { public int Id { get; set; } public string Text { get; set; } public Answer[] Answers { get; set; } } public class Answer { public int Id {get; set; } public string Text { get; set; } } Using EF6 Code First I've setup this simple DbContext: public class MyContext : DbContext { public MyContext() { Database.SetInitializer<MyContext>(new DropCreateDatabaseAlways<MyContext>()); } public

Should EF's DbContext contains all tables?

南笙酒味 提交于 2021-02-07 06:52:48
问题 I'm new to EF4, and I'm trying to figure out the best way to create my DbContext class(es). Is there any problem (specially performance) in putting all my tables / entities into one and only one DbContext class, like the code below? public class AllInOneDb : DbContext { public DbSet<Customer> Customers{ get; set; } public DbSet<Address> Addresses{ get; set; } public DbSet<Order> Order{ get; set; } public DbSet<Product> Products{ get; set; } public DbSet<Category> Categories{ get; set; } //

MySQL Data Provider Not Showing in Entity Data Model Wizard

懵懂的女人 提交于 2021-02-07 06:24:53
问题 I am creating an MVC application with MySQL as backend. I am planning to use Entity Framework to work with this database. I already have a database so need to generate models from a database Environment: MySQL Server 5.7.21 MySQL for Visual Studio 1.27 Connector/NET 6.10.5 Visual Studio 2015 To Reproduce Issue: Step 1: Add new item 'Ado.net Entity Data Model' Step 2: Selected 'EF Designer from database' and click 'Next' Step 3: Clicked 'New Connection' There is no mysql connector available.

MySQL Data Provider Not Showing in Entity Data Model Wizard

那年仲夏 提交于 2021-02-07 06:24:47
问题 I am creating an MVC application with MySQL as backend. I am planning to use Entity Framework to work with this database. I already have a database so need to generate models from a database Environment: MySQL Server 5.7.21 MySQL for Visual Studio 1.27 Connector/NET 6.10.5 Visual Studio 2015 To Reproduce Issue: Step 1: Add new item 'Ado.net Entity Data Model' Step 2: Selected 'EF Designer from database' and click 'Next' Step 3: Clicked 'New Connection' There is no mysql connector available.