ef-code-first

EF6 and pre-generated views

让人想犯罪 __ 提交于 2019-12-11 01:19:33
问题 I am using EF code first method in my project. Recently I updated EF version of my project to EF 6 using Package Manager Console. All of my entities are inherited from a BaseEntity class as a super class : public abstract class BaseEntity { public virtual int Id { get; set; } States _state; [NotMapped] public States State { get; set;} public enum States { Unchanged, Added, Modified, Deleted } .... } And also I don't add the BaseEntity in my DbContext , the program run without any problem, but

How to scaffold EF core to existing DB?

非 Y 不嫁゛ 提交于 2019-12-11 00:59:30
问题 I am trying to reverse engineer an existing database using Entity Framework Core . I tried to follow the directions from Microsoft but I am presented with the error: Unable to find provider assembly with name EntityFramework. Ensure the specified name is correct and is referenced by the project. I am running the following command from the project directory: dnx ef dbcontext scaffold "Server=REMOVED;Database=REMOVED;User ID=REMOVED;Password=REMOVED" EntityFramework What am I doing wrong? 回答1:

Map weak entity by using Code first

我的未来我决定 提交于 2019-12-11 00:49:07
问题 Hi I have developed model that works perfectly for me, now I want to map it to database using EntityFramework, here is a part of it: public class Product { public int Id { get; set; } public string Name { get; set; } public virtual ProductType Type { get; set; } } public class Supplier { public int Id { get; set; } public string OIB { get; set; } public string Name { get; set; } } public class SupplierProduct { public double Price { get; set; } public string SupplierMark { get; set; } public

Let Entity Framework (code first) ignore an indexed property

点点圈 提交于 2019-12-11 00:39:45
问题 In an entity I have following declaration: Default Property Item(key As String) As String Because Entity Framework doesn't like indexed properties I've tried to ignore it: Public Class EntityMap Inherits EntityTypeConfiguration(Of EntityMap) Public Sub New() ' Me.Ignore(Function(x) x.Item()) --- Missing index parameter, compiler error ' Me.Ignore(Function(x) x.Item(String.Empty)) --- Gives runtime error End Sub End Class I've also tried to remove all discovery conventions from modelBuilder so

Soft Delete on Entity Framework Many-to-Many Mapping

懵懂的女人 提交于 2019-12-11 00:06:51
问题 I have a many to many EF map similar to the example below. I am using EF code first approach so my mapping class inherits EntityTypeConfiguration<>. this.HasMany(a => a.KPIs) .WithMany() .Map(a => { a.ToTable("KeyResultArea_KeyPerformanceIndicator_Mapping"); a.MapLeftKey("KRA_Id"); a.MapRightKey("KPI_Id"); }); As a result of this im left with the schema shown below. No great surprises so far. - However I would like to be able to soft delete one of these mappings so my desired schema would

Entity Framework Code First TPC Inheritance Self-Referencing Child Class

做~自己de王妃 提交于 2019-12-10 23:49:11
问题 I have a problem With Entity Framework and TPC Inheritance With Self-Referencing Child Class. My Class definitions: Public Class BaseObject <Key()> <DatabaseGenerated(DatabaseGeneratedOption.None)> Public Overridable Property iId As Integer <Required()> Public Property iModUserId As Integer <ForeignKey("iModUserId")> Public Property ModUser As User <Required()> Public Property dtModDate As DateTime End Class Public Class User Inherits BaseObject <Required()> Public Property sFirstName As

entity framework code first and view mapping

[亡魂溺海] 提交于 2019-12-10 21:55:33
问题 I have a application using code first; in search section I have to gather information from 3 tables and their related tables so I made a view; and since there is no syntax for code first to create view (I think so; please let me know if I'm wrong) I used pure SQL script; on model creating to prevent EF to create a table with same name as table (VIEW_SEARCH) I did : protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Ignore<View_Search>(); } any ways application

Entity Framework Migration Adding Column Twice

点点圈 提交于 2019-12-10 21:27:09
问题 I'm running Entity Freamework Code First Migrations. When trying to run the application I get the error: A column ID occurred more than once in the specification. I have AutomaticMigrationsEnabled set to true in the configuration because when I run the project, I want the migrations to run automatically. This is the verbose results when I tried running it through the package manager: Applying code-based migration: 201211261626569_AddActiveFlagForProjects. ALTER TABLE [Projects] ADD [Active]

Cannot attach the file ‘{0}' as database '{1}'. Code first. Local SQL EXPRESS Instance. VS 2010 SP1. Windows XP

荒凉一梦 提交于 2019-12-10 20:43:41
问题 I've been using Code First approach. I created a sql express local database "Database.mdf" in Visual Studio 2010 SP1 using MVC 4 template. When I try to run my project at my PC, I get an error: CREATE DATABASE permission denied in database master. Cannot attach the file "...Database.mdf" as database file "Database". What I've tried: deletion my database using SQL SERVER Object explorer(no results, the same error) change connection string (no result, the same error) googled in the Internet.

Entity Framework Code First - Ignore complete entity

我是研究僧i 提交于 2019-12-10 20:11:45
问题 Is there an easy solution for the following situation: I've got an Entity Dossier which is shared in 2 DbContexts . Dossier has 2 navigation properties, DossierType and DossierAttachment Dossier Dossier --> DossierType (Navigation Property) Dossier --> DossierAttachment (Navigation Property) I want to exclude the DossierType Entity in DbContext1 . I do not want it to be savable to database, navigation properties should not be set. I was expecting that calling modelBuilder.Ignore<DossierType>(