entity-framework-6

How to pass null values into stored procedure via Entity Framework?

微笑、不失礼 提交于 2019-12-13 15:21:12
问题 I am using an ASP.NET MVC 4 application with Entity Framework. I want to pass null values conditionally, let's say if pass value into DeptID then it should list of values for only passed DeptID , and if pass DeptID = NULL then it should it all the departments. I wrote a procedure by checking DeptID and it returns the desired output (if DeptID is null , then all rows are returned). But problem is to when I want to pass null values through following code of Entity Framework it is not working.

“The provider did not return a ProviderManifestToken string” MySQL with Entity Framework

。_饼干妹妹 提交于 2019-12-13 15:13:00
问题 I have set up a new project in VS 2017. My intention is to use EF CodeFirst approach. So far I used Azure SQL Database, while in this test project I want to use my remote MySQL database. I have created the user and permissions are set just right. This remote database server is accessible to me over MySQL Workbench. I have created a new blank MVC project and through Nuget I installed MySQL.Data.Entity (version 6.9.10). My Context class: [DbConfigurationType(typeof(MySqlEFConfiguration))]

Many-To-Many Generic Update Method with Entity Framework 6

北慕城南 提交于 2019-12-13 14:03:28
问题 I have a generic Update method for Entity Framework in an abstract DatabaseOperations<T,U> class: public virtual void Update(T updatedObject, int key) { if (updatedObject == null) { return; } using (var databaseContext = new U()) { databaseContext.Database.Log = Console.Write; T foundEntity = databaseContext.Set<T>().Find(key); databaseContext.Entry(foundEntity).CurrentValues.SetValues(updatedObject); databaseContext.SaveChanges(); } } However, this does not handle many-to-many relationships.

What is the replacement in Visual Studio 2017 for Entity Framework 'database first'

为君一笑 提交于 2019-12-13 13:27:12
问题 Simple question - I'm working in Visual Studio 2017 and while I know that the 'database first' approach in EF is gone, I'm wondering what the replacement is. What I specifically would like to do is generate classes from an existing database. I see this: EntityFramework Reverse POCO Generator - is this the right option, or is there something in VS2017 I should be using? I would think that this would be obvious information, maybe I'm looking in the wrong place... Note: I have an ASP.NET Core

How to make the AddOrUpdate run in order in DbMigrationConfiguration Derived class

こ雲淡風輕ζ 提交于 2019-12-13 10:27:52
问题 I enabled the migration, and I code the seed codes like follow: protected override void Seed(DbContext c) { c.DbSet<Table1>.AddOrUpdate(..); c.DbSet<Table2>.AddOrUpdate(..); c.DbSet<Table3>.AddOrUpdate(..); } I need the table1 run in order, because the table2 references table1, and the table3 references table1 and table2. but the EF6 has optimized the code generated T-SQL batchs, they query the table1 for table3's references, and there is nothing due to table1 hasn't initialized yet, and EF6

Seeding data will not work when schema changes with Code First when using migrations

我是研究僧i 提交于 2019-12-13 08:53:21
问题 Okay so I am using Entity Framework 6.1 and attempting code first with seeding. I have a drop always intializer that ALWAYS WORKS. However I want to use database migration which I have set up and it works. UNTIL I normalize out a table and then try to seed it I get a primary key error. Basically in my context when I uncomment out the changes in the 'TODO' section and the schema changes I get a primary key violation when attempting population of the newly normalized out table. It will work for

How to joint two set of retrieved data using LinQ To Entities

霸气de小男生 提交于 2019-12-13 07:44:48
问题 I am using dbcontext Code first to get a query base on this condition for the Classes (tables) below: Creator != null && ArticleAttached != null && !IsCancelled Problem : How to get data from the classes (tables) and show Article Title, No. of Likes, No. Of Comments, Total Assigned, TotalResponded A) I use dbcontext as follows: var ListArticles = dbcontext.LearningActivites .Where(la => la.Creator != null && la.ArticleAttached != null && !la.IsCancelled) .Select(la => new { Id = la.Id, Title

How can it take 0 ticks to query the database asynchronously?

余生颓废 提交于 2019-12-13 07:23:29
问题 I'm trying to use IDbInterceptor to time Entity Framework's query executions, as accurately as possible, implementing a variant of Jonathan Allen's answer to a similar question: public class PerformanceLogDbCommendInterceptor : IDbCommandInterceptor { static readonly ConcurrentDictionary<DbCommand, DateTime> _startTimes = new ConcurrentDictionary<DbCommand, DateTime>(); public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { Log(command,

Paging with 3 sub-queries with 1 connection vs 2 Queries with 2 connections

六月ゝ 毕业季﹏ 提交于 2019-12-13 07:22:54
问题 I have been doing a lot of research on Paging and I am stuck between two methods. With both approaches I will be using PagedList.MVC to display my pages, however the problem lies in how do I pass the data to the PagedList and which of my two methods is more efficient. The best example I have found out there is as follows: public static PagedList<Customer> GetPagedCustomers(int skip, int take) { using (var context = new AdventureWorksLTEntities()) { var query = context.Customers.Include(

EF Applies All Migrations, Not Just New One

只谈情不闲聊 提交于 2019-12-13 07:22:31
问题 I'm using EF 6 and when I run Update-Database it is trying to apply every migration since the beginning of the project, even though there is only migration that is new. If I attempt to create an empty migration, I get an error that says I can't create a new migration because there are explicit migrations pending. The only blog post I found with a similar issue suggested dropping the __MigrationHistory table and doing Update-Database -Script , stripping out all the actual DB changes but