entity-framework-6

Entity Framework 6 & TPH inheritance: Map properties with the same name to same column by default

£可爱£侵袭症+ 提交于 2019-12-03 12:44:37
As of EF6 it is possible to do something like this when configuring Entity mappings using Table Per Hierarchy inheritance: public class MyContext : DbContext { public DbSet<Device> Devices { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<ABatteryPoweredDevice>().Property(c => c.BatteryLevel).HasColumnName("BatteryLevel"); modelBuilder.Entity<ADifferentBatteryPoweredDevice>().Property(c => c.BatteryLevel).HasColumnName("BatteryLevel"); } } BatteryLevel is not part of the Device base class- it is a property of the derived classes

Entity Framework 6 (code first) entity versioning and auditing

送分小仙女□ 提交于 2019-12-03 12:41:00
问题 I'm looking at using Entity Framework 6.1.1 with SQL Server 2008 R2. Currently I'm creating my models and database using the code-first EF feature. My basic use-case is to create a journal of all changes to a particular entity ( ID is the key column) to help auditors track all changes made and by whom. e.g: |ID|Version|Created Date|Created By|Modified Date|Modified By|Modify Action| ... (rest of entity fields) -----------------------------------------------------------------------------------

EntityFramework.SqlServer.dll not is getting added to the published folder only when I publish in RELEASE mode

懵懂的女人 提交于 2019-12-03 12:25:02
I know there is a problem with EF6 EntityFramework.SqlServer and included var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices); in context constructor. It works fine when i do publish in DEBUG mode. Getting the below error only when I publish in RELEASE mode. The reason is EntityFramework.SqlServer.dll missing in the published folder. But, bin folder has EntityFramework.SqlServer.dll for both debug and release mode. Error: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for

How do I use spatials to search a radius of zip codes?

廉价感情. 提交于 2019-12-03 12:03:27
问题 Background I'm writing an application which finds events within a certain radius of a zip code. You can think of this like ticketmaster, where you type in your zip code and all of the concerts in the radius of x show up. I have a database table which has the zip code, and each zip codes' Latitude and Longitude. I also have an 'EventListings' table where each 'Event' has a ZipCode field. Problem Currently, I'm using the Haversine formula in a Linq-to-Entities query in my service layer to find

How do I create connection string programmatically to MS SQL in Entity Framework 6?

自古美人都是妖i 提交于 2019-12-03 11:30:29
How do I create connection string programmatically to MS SQL in Entity Framework 6? I'm using c# and WPF and I was wondering if someone could show me how or link me to a resource that shows how to set up connection strings programmatically in EF 6. The MSDN article explains that you can http://msdn.microsoft.com/en-us/data/jj680699#moving but it doesn't go into creating actual connection strings. So here is an EF6 example that works App.Config entityFramework codeConfigurationType="WPFwithEF.SqlConfiguration, WPFwithEF"> /entityFramework context public class ProductContext : DbContext { public

Net Core 2 - Entity Framework: Update-Database of different environment

≯℡__Kan透↙ 提交于 2019-12-03 09:41:27
FACTS: net core 2.0 project entity framework (code first) different appsettings.json file for different environments I utilize Package Manager Console to generate my DB scripts (Add-Migration, Update-Database) If I run PM>"Get-DbContext" it brings back info pulled from my appsettings.Development.json file GREAT, that's what I want most of the time! But how do I tell it to pull db variables from appsettings.Staging.json instead of development for PM commands? I tried creating new launchSettings.json profiles and setting "ASPNETCORE_ENVIRONMENT": "Staging" but everything seems to respect that

How to get original Entity from ChangeTracker

一笑奈何 提交于 2019-12-03 09:23:09
问题 Is there a way to get the original Entity itself from the ChangeTracker (rather than just the original values)? If the State is Modified , then I suppose I could do this: // Get the DbEntityEntry from the DbContext.ChangeTracker... // Store the current values var currentValues = entry.CurrentValues.Clone(); // Set to the original values entry.CurrentValues.SetValues(entry.OriginalValues.Clone()); // Now we have the original entity Foo entity = (Foo)entry.Entity; // Do something with it... //

Is there an EF6 DbContext Generator for C# which uses Fluent API?

这一生的挚爱 提交于 2019-12-03 09:20:03
I know that the EF6 VS Tools for Visual Studio 2012 come with a T4 template to generate DbContext classes which work with EF6. But I want to have a generator which uses fluent API. The older version I used with EF4 and EF5 don't work with EF6 and the author no longer works on them to make them EF6 compatible. Is anyone else working on a generator which uses Fluent API which works with EF6? http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d If you have a database you can use reverse code first it will generate all your fluent api mapping. 来源: https:/

Query Xml from SQL using Entity Framework Database First

你离开我真会死。 提交于 2019-12-03 08:34:18
I need to use Entity Framework, LINQ to query the XML data from the SQL in my asp.net mvc(C#) application. I have a column XMLValue with data <MetaData> <Reviews>1</Reviews> <Rating>1</Rating> </MetaData> I need to get all the Customers who have a Rating of 1 from the xml. I have referred to this stackoverflow post and I am not able to achieve it. I have added the SQL function and added it to my edmx: CREATE FUNCTION [dbo].[FilterCustomersByRating] (@Rating int) RETURNS TABLE AS RETURN SELECT XMLTest.* FROM XMLTest CROSS APPLY XMLValue.nodes('//MetaData') N(C) where N.C.value('Rating[1]', 'int

How to get id from entity for Auditlog in Entity Framework 6

醉酒当歌 提交于 2019-12-03 08:26:56
问题 I know it's several similar posts out there, but I cannot find any with a solution to this issue. I want to add a (sort of) AudioLog when adding, changing or deleting entities (soft-delete) in Entity Framework 6. I've overridden the SaveChanges and because I only want to add log entries for EntityStates Added, Modified or Deleted, I fetch the list before I call SaveChanges the first time. The problem is, because I need to log what operation has been executed, I need to inspect the EntityState