entity-framework-6

Is it possible to configure a custom provider for migrate.exe without using the machine.config

。_饼干妹妹 提交于 2019-12-11 10:24:49
问题 I am trying to setup automated migrations using migrate.exe that is provided in the EntityFramework v6 nuget package. My application uses a PostgreSQL database and uses a custom database provider (Npgsql), which requires additional configuration for EntityFramework. Migrate.exe works successfully if I add the required configuration into the machine.config, however this is not a practical solution as it requires editing the machine.config everywhere the migrations are run. I also want to set

EF multiple foreign key relationship on same primary key

走远了吗. 提交于 2019-12-11 09:57:32
问题 I want to create a many-to-many relationship using EF 6 using a code-first approach. My entities use a composite primary key (to handle multi-tenancy). Let's take simple and classical example. I have two entities Project and Person which have a many-to-many relationship: public class Person { [Key, Column(Order = 1),] public Int32 Id { get; set; } [Key, Column(Order = 2)] public int TenantId { get; set; } public string Name { get; set; } } public class Project { [Key, Column(Order = 1),]

Entityframework model first decimal precision

Deadly 提交于 2019-12-11 09:57:14
问题 I'm using Entityframework 6 with model first. In the diagram I have chosen decimal for my datatype. When I save decimal values, the database only has whole numbers and the decimals get dropped. My first suspicion was to check the precision, however going to the properties window from the model first diagram designer, the precision and scale dropdowns have no other options besides "None". How do I get EF to save my decimals? Is it a precision issue? If so, how do I set the precision in this

Use MySQL and MSSQL in Entity Framework 6

≯℡__Kan透↙ 提交于 2019-12-11 09:44:17
问题 I'm developing a webservice. Behind this service are two methods: One to get entities from a MySQL Connection and the other to get entities from a MSSQL Server Connection. I have two connection strings. I would like to have two contexts, they are completely separated. But i'm not able to manage this. Any ideas? 回答1: The solution was simple in the end. Be sure to install MySql Connector/Net on all target systems! I missed this on my target platform. web.config / app.config: <configuration>

Entity Framework Table Per Class Inheritance

可紊 提交于 2019-12-11 09:18:33
问题 I am trying to implement a history table for an entity in EF6, code first. I figured there would be a way to do this with inheritance. The history table, which is a derived type of the actual table entity, just containing straight copies of all the properties. Along with an edit to the key. My code first table entity config for Booking . public class BookingEntityConfiguration : EntityTypeConfiguration<Booking> { public BookingEntityConfiguration() { Property(b => b.BookingId).HasColumnOrder

Issue with many-to-many relationship + TPH inhertitance in Entity Framework 6

坚强是说给别人听的谎言 提交于 2019-12-11 09:09:29
问题 I am running into an issue with EF6, though I'm fairly sure that this applies to previous versions that support this type of mapping. I fear I know the answer to the question at hand, but I hope that I am doing something wrong, or there is a better workaround than what I present here. All classes are gutted for clarity. So I have public abstract class SoftwareFirmware { public long Id { get; private set; } public ICollection<DeviceType> DeviceTypes { get; private set; } public

Cannot use Entity Framework in .NET standard 2 project

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 08:53:31
问题 How can I use Entity Framework, or something similar within a .NET Standard project? It appears as though EF is not supported in .NET Standard 2 which is really annoying! So I have tried using Microsoft.EntityFrameworkCore.SqlServer and icrosoft.EntityFrameworkCore.SqlServer.Design Whist I can install these packages, I cannot then add a model I get the error --------------------------- Microsoft Visual Studio --------------------------- The project's target framework does not contain Entity

Unable to write an Include query with FirstOrDefault() and condition

巧了我就是萌 提交于 2019-12-11 08:04:51
问题 I'm writing an entity framework query which needs Eager loading multiple levels based on condition. var blogs1 = context.Blogs .Include(x => x.Posts.FirstOrDefault(h => h.Author == "Me")) .Include(x => x.Comment) .FirstOrDefault(); public class Blog { public int BlogId { get; set; } public virtual ICollection<Post> Posts { get; set; } } public class Post { public int PostId { get; set; } public string Author { get; set; } public int BlogId { get; set; } public virtual ICollection<Comment>

How to remove Many to Many auto generated table with Entity Framework Code First

我怕爱的太早我们不能终老 提交于 2019-12-11 07:53:37
问题 I have 3 Entities Product , Supplier & Contract , Product & Supplier each have as reference a Collection of each other which creates a ProductSupplier Table. To add an extra property on this Many to Many relation i have created a 3rd Entity ProductForSupplier wich holds 1 Product, 1 Supplier and a extra string Property ProductNumber. In addition i have created another Entity ProductSupplierForContract which holds a ProductForSupplier & a Contract. When i seed some data for test i can observe

C# EntityFramework 6.0 - How to use Where Statement in EntityTypeConfiguration?

為{幸葍}努か 提交于 2019-12-11 07:18:45
问题 I have 2 classes like this: Parent.cs public class Parent { public int Id {get;set;} public virtual ICollection<Child> Children { get; set; } } Child.cs public class Child { public int Id {get;set;} public ItemStatusType ItemStatusTyp { get; set; } public int ParentId {get;set;} [ForeignKey("ParentId")] public virtual Parent Parent { get; set; } } ItemStatusType.cs public enum ItemStatusType { Active = 1, Deactive = 2, Deleted = 3 } What I want is to somehow retrieve always the active ones