dbcontext

Using EF DbContext with mysql and sql in the same project

ぐ巨炮叔叔 提交于 2021-02-16 15:23:56
问题 I'm working on an ASP.net MVC project using EF in combination with MySql. Now this works just fine on its own but I also want to reference another class library that uses EF with SQL. When I reference the library EF seems to get confused on what provider to use for each DbContext. On my MySql DbContext I have the following attribute in order to tell EF this DbContext should be handled by the MySql provider: [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] Now on the SQL

Using EF DbContext with mysql and sql in the same project

我们两清 提交于 2021-02-16 15:23:47
问题 I'm working on an ASP.net MVC project using EF in combination with MySql. Now this works just fine on its own but I also want to reference another class library that uses EF with SQL. When I reference the library EF seems to get confused on what provider to use for each DbContext. On my MySql DbContext I have the following attribute in order to tell EF this DbContext should be handled by the MySql provider: [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] Now on the SQL

MVC Core 3 FromSqlRaw parameters not working as expected

好久不见. 提交于 2021-02-11 15:38:38
问题 Has anyone else run into the issue of FromSqlRaw parameters not working as expected? There is a Gotcha to be aware of. With the latest MVC Core 3 DbContext I added a stored procedure but could not get the FromSqlRaw call to correctly evaluate parameters. SqlParameter[] parameters = { new SqlParameter("DateFrom", dateFrom), new SqlParameter("DateTo", dateTo), new SqlParameter("Sort", sort), new SqlParameter("Aggregation", aggregation) }; return await sp_Visits.FromSqlRaw("EXECUTE dbo.sp_Visits

MVC Core 3 FromSqlRaw parameters not working as expected

眉间皱痕 提交于 2021-02-11 15:36:34
问题 Has anyone else run into the issue of FromSqlRaw parameters not working as expected? There is a Gotcha to be aware of. With the latest MVC Core 3 DbContext I added a stored procedure but could not get the FromSqlRaw call to correctly evaluate parameters. SqlParameter[] parameters = { new SqlParameter("DateFrom", dateFrom), new SqlParameter("DateTo", dateTo), new SqlParameter("Sort", sort), new SqlParameter("Aggregation", aggregation) }; return await sp_Visits.FromSqlRaw("EXECUTE dbo.sp_Visits

Storing custom class property like String via OnModelCreating of DBContext .Net Core

孤人 提交于 2021-02-11 12:22:22
问题 I have two classes in .Net Core The class Owner namespace CustomStoreDatabase.Models { public class Owner { public string OwnerId { get; set; } public DateTime MinDateTime { get; set; } public DateTime MaxDateTime { get; set; } public TimeSpan Interval { get; set; }//store like a double public Ownership Ownership { get; set; } //store like a JSON String in the db } } And the class Ownership namespace CustomStoreDatabase.Models { public class Ownership { public string OwnershipId { get; set; }

ASP.NET Core re-registering dbcontext after changing connection string

守給你的承諾、 提交于 2021-02-08 06:43:27
问题 I have an ASP.NET Core application that has a connection string key in the config file. If its value is not correct (for example database name, ip address, etc), i wish to be able to re-register this dbcontext service with the new connection string after the user has changed it manually in the config file. How to achieve this? Is this considered a bad practice? Thank you. 回答1: I see that you are using asp.net core. Ideally you should not change your connection string when the application is

Entity Framework always save DateTimeOffset as UTC

巧了我就是萌 提交于 2021-02-08 02:21:12
问题 Is there a way that I can instruct Entity Framework to always store DateTimeOffset as the UTC value. Technically there is no reason for this but I prefer it if all the data in my database is consistent. Currently it is storing the DateTimeOffset as received from the client which could be anything depending on the users locale. I was thinking of perhaps intercepting all the SaveChanges method, looping through the changes, looking for DateTimeOffset types and doing the conversion explicitly,

Entity Framework always save DateTimeOffset as UTC

元气小坏坏 提交于 2021-02-08 02:19:47
问题 Is there a way that I can instruct Entity Framework to always store DateTimeOffset as the UTC value. Technically there is no reason for this but I prefer it if all the data in my database is consistent. Currently it is storing the DateTimeOffset as received from the client which could be anything depending on the users locale. I was thinking of perhaps intercepting all the SaveChanges method, looping through the changes, looking for DateTimeOffset types and doing the conversion explicitly,

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

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; } //