entity-framework-6

Add-Migration without parameterless DbContext and DbContextFactory constructor

早过忘川 提交于 2021-02-08 14:15:19
问题 My application has no parameterless constructor at my DbContext implementation and I don't like to provide a parameterless constructor to a IDbContextFactory<> implementation. The reason is I want to keep control where the DbContext points to. That's why all my constructors will ask for the ConnectionStringProvider. public class MyDbContext : DbContext { internal MyDbContext(IConnectionStringProvider provider) : base(provider.ConnectionString) {} } and public class MyContextFactory :

entity framework update nested objects

馋奶兔 提交于 2021-02-08 11:27:31
问题 I am trying to perform an update through EF 6 and having trouble. I am relatively new to EF so please forgive me if the question is a bit dim. I am getting the following error When I try and update the instrument table: The entity type HashSet`1 is not part of the model for the current context. I think this is because of the nested objects. Does anyone know how to populate these? Thanks in advance. please see the code below of my update and model. try { var i = (from x in _entities.Instrument

Entity Framework 6 query returning record with data not yet saved in the database

纵然是瞬间 提交于 2021-02-08 07:51:14
问题 I created a very simple test project using Entity Framework 6 Code-first and I'm trying to understand how change tracking works. In my simple test I have a Blogs table and I insert a Blog with a name "User1", after inserting and saving I modify the object used to insert (name="User1 modified") but without saving changes. Right after that I query my database. For my surprise the query from the db is returning the modified record even though I did not save my changes after the update. Why is

Entity Framework Plus - FutureValue() in a foreach loop

怎甘沉沦 提交于 2021-02-08 07:33:27
问题 Recently I started using EF+ on our project with great success however sometimes I run into an issue that I have a set of entities for which I need to run a separate query. So if I have a set of 20 customers I need to run 20 queries separately. I wonder if there is way how to avoid this using EF+ FutureValue() somehow in a foreach loop. See this sample code: foreach (var customer in customers) { customer.SomeValue = ctx.SomeDatabaseTable.Where(myCondition).FutureValue(); // this would run 20

Entity framework override save changes to soft delete entities

北城以北 提交于 2021-02-08 05:37:15
问题 I am trying to override Savechanges in My Database Context to mark my entites as SoftDeleted. I have an ISoftDeletable base which i override in my Entity classes public interface IsoftDeletable { public bool IsDeleted {get; set;} } And then in my Context public override int SaveChanges() { foreach (var entry in ChangeTracker.Entries() .Where(p => p.State == EntityState.Deleted)) SoftDelete(entry); return base.SaveChanges(); } private void SoftDelete(DbEntityEntry entry) { var entity = entry

Oracle Data Provider for .NET does not support Oracle 19.0.48.0.0

拥有回忆 提交于 2021-02-08 02:08:27
问题 We just upgraded to Oracle 19c (19.3.0) and all apps stopped working with this error message: Oracle Data Provider for .NET does not support Oracle 19.0.48.0.0 I updated Oracle.ManagedDataAccess.EntityFramework and Oracle.ManagedDataAccess to 19.3.0 Any solution? 来源: https://stackoverflow.com/questions/57717088/oracle-data-provider-for-net-does-not-support-oracle-19-0-48-0-0

FUNCTION database.AddDays does not exist

夙愿已清 提交于 2021-02-07 18:17:26
问题 I'm trying to use dbfunction from EF6 on database MySQL but I get the follow exception "FUNCTION database.DiffDays does not exist". I used this code: var aux = bd.Atos.Where(w => w.IdAtivo == 1 && w.IdUtilizador == idUtilizador && DbFunctions.DiffDays(DbFunctions.AddDays(w.Data, w.NumDias).Value, DateTime.Now).Value < numeroDias) What I'm missing? 来源: https://stackoverflow.com/questions/24442260/function-database-adddays-does-not-exist

FUNCTION database.AddDays does not exist

独自空忆成欢 提交于 2021-02-07 18:16:41
问题 I'm trying to use dbfunction from EF6 on database MySQL but I get the follow exception "FUNCTION database.DiffDays does not exist". I used this code: var aux = bd.Atos.Where(w => w.IdAtivo == 1 && w.IdUtilizador == idUtilizador && DbFunctions.DiffDays(DbFunctions.AddDays(w.Data, w.NumDias).Value, DateTime.Now).Value < numeroDias) What I'm missing? 来源: https://stackoverflow.com/questions/24442260/function-database-adddays-does-not-exist

Entity Framework 6 - Query Performance

时间秒杀一切 提交于 2021-02-07 10:04:36
问题 I use Entity Framework 6 and i currently have a query with many includes which loads about 1200 entities into the dbContext. Loading the entities seems to be quite slow as the query takes almost a minute. Is there anything I can do about the performance? I have 4 such queries that take 2.5 minutes to load? LazyLoading is enabled but for performance reasons i preload the entities. var report = DbContext.REPORT.Single(r => r.ID == reportId); //this query takes a bit less than 1 minute DbContext

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 =