entity-framework-6

How can I get the parameters of an Entity Framework query?

坚强是说给别人听的谎言 提交于 2019-11-29 12:16:54
If I create a query of IQueryable<T> , I can call .ToString() to get the SQL that will be called, but that SQL may contain parameters like @p__linq__0, @p__linq__1, etc. Is there a way to get those parameters and their values from the IQueryable<T> It's frustratingly complicated, in my experience, but this code got me there: var dbQuery = (DbQuery<T>)query; // get the IInternalQuery internal variable from the DbQuery object var iqProp = dbQuery.GetType().GetProperty("InternalQuery", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); var iq = iqProp.GetValue(dbQuery, null);

How to disable model caching in Entity Framework 6 (Code First approach)

纵然是瞬间 提交于 2019-11-29 11:56:01
问题 Following MSDN documentation we can read: The model for that context is then cached and is for all further instances of the context in the app domain. This caching can be disabled by setting the ModelCaching property on the given ModelBuidler , but note that this can seriously degrade performance. The problem is the model builder does not contain any property named ModelCaching . How it is possible to disable the model caching (e.g. for changing model configuration in a run-time)? 回答1: I have

How to programatically create Sql Azure database of type Basic/Standard edition through Enity Framework code first

早过忘川 提交于 2019-11-29 11:45:54
I use EF 6. My existing code is : public void CreateOrUpdateCompanyDb(string companyDbName) { try { string connectionString = _connectionStringProvider.GetConnectionString(companyDbName); DbMigrationsConfiguration cfg = CreateMigrationsConfig(connectionString); cfg.AutomaticMigrationsEnabled = false; cfg.AutomaticMigrationDataLossAllowed = false; DbMigrator dbMigrator = new DbMigrator(cfg); dbMigrator.Update(); } catch (MigrationsException exception) { _logger.Error(string.Format("Error creating company database '{0}'",companyDbName), exception); } } with connection string as follows : Server

How do I add an additional column to the __MigrationHistory table?

不问归期 提交于 2019-11-29 11:41:51
Per Customizing the Migrations History Table , I should be able to add a column, however I'm not able to find any examples on how to actually add the new column. I'm mostly confused about where to put the actual property and how to configure it to the existing __MigrationHistory table. From the documentation, I can customize the table configuration like so.. protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<HistoryRow>().ToTable(tableName: "MigrationHistory", schemaName: "admin"); modelBuilder.Entity<HistoryRow>()

How to resolve Warning : The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 11:34:44
问题 I'm playing around with EF different workflows. Yesterday I made a new project and Entity Framework 6 was the first suggestion from Nuget so I decided to give it a try, also it is a very small project entirely for learning purposes so I guess it will be good experience to try EF 6 since I've been working mostly with Ef 5 . My Application is based on Code First approach. The structure of the solution is shown in the print screen: The project CodeFirstClasses is meant to hold my Entites. For

Entity Framework List Contains in lambda

老子叫甜甜 提交于 2019-11-29 11:23:59
I want to query items with specific IDs using. For example: var ids = new List<int> { 1, 3, 5 }; var items = context.Items.Where(item => ids.Contains(item.ID)).ToList(); Questions: Will this generate a single query with SQL IN operator? Is this code OK in terms of performance? Are there any better ways to do it? I am using Entity Framework 6 with Microsoft SQL Server. Will this generate a single query with SQL IN operator? Yes Is this code OK in terms of performance? Yes (for small lists) Are there any better ways to do it? No (for small lists) If the list is really big and the table is

Unable to determine the provider name for provider factory of type 'System.Data.SQLite.SQLiteFactory'. with the Nuget package version 1.0.94.1

霸气de小男生 提交于 2019-11-29 11:13:33
问题 I am getting this error with the Nuget package for SQLite 1.0.94.1. I fiddled around with the various app.config sections, helped by similar questions about previous versions of this package, but I cannot get it to work. Below is the app.config as I found it after installing the Nuget package. I deleted the app.config prior to installing it. I only added the connectionstrings after that. So, where is the problem?? <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections>

Using DateDiff with Linq.Dynamic library for fetching today records

二次信任 提交于 2019-11-29 10:22:37
I am trying to fetch all records added today using DateDiff SQL syntax via Linq expression in MVC 5 / Entity Framework 6 application. DateDiff function throw runtime error Actually i want to the following linq WHERE clause to parse with linq dynamics .Where(p => DbFunctions.DiffDays(p.added_date, DateTime.Now) == 0) in order to fetch today added records. Sample code that i am using shown below var _list = new vsk_error_log(); using (var entities = new vskdbEntities()) { _list = entities.vsk_error_log //.Where("DateDiff(DAY,added_date,getdate())=0") .Where(p => DbFunctions.DiffDays(p.added_date

How to enable migrations (EF6) in an asp.net 5 project?

孤街醉人 提交于 2019-11-29 09:32:57
I created a new class library (package) project (prior to VS 2015 RC used the even worse name of asp.net class library to represent the data layer. Just to be clear this is the newer kproj style structure. Added EF 6.1.3 to project.json. Currently only targeting DNX451. "dependencies": { "EntityFramework": "6.1.3" ,"Moq": "4.2.1502.911" }, Created initial model classes and using a AlwaysCreate database initializer everything works fine. Now need to switch to migrations so used Enable-Migrations in the package manager console and got: Enable-Migrations : The term 'Enable-Migrations' is not

Entity Framework Code First truncating my decimals

五迷三道 提交于 2019-11-29 09:25:23
I am using Entity Framework 6.x using the Code First approach on an MVC 5 application. In this particular situation my model (among other things) contains two properties named Latitude and Longitude: [Required, Range(-90, +90)] public decimal Latitude { get; set; } [Required, Range(-180, +180)] public decimal Longitude { get; set; } And when I performed the migration I got something like this CreateTable("ResProperty"), c => new { : Latitude = c.Decimal(nullable: false, precision: 10, scale: 8), Longitude = c.Decimal(nullable: false, precision: 11, scale: 8), : }) ... other stuff so both