entity-framework-6

How can I serialize a DbCompiledModel from EF6?

女生的网名这么多〃 提交于 2019-12-10 18:13:57
问题 I'm pursuing a suggestion made on this question: EF6 code first: How to load DbCompiledModel from EDMX file on startup? I want to serialize a DbCompiledModel to disk, so I can deserialize it later and improve startup time. It needs to serialize properties and fields including private ones. My three attempts below have failed for the following reasons. How else could I serialize the private contents of DbCompiledModel? BinaryFormatter My first attempt via BinaryFormatter: var compiledModel =

Prevent Adding New Record on Related Table Entity in Entity Framework

我只是一个虾纸丫 提交于 2019-12-10 18:10:00
问题 I am trying to add new record on my entity. It works fine, the problem is, the related entities are adding new records as well. Is there a way to stop related or 2nd level entities to be inserting new records as well? Here is my sample Entity Class: public Tracking() { public string Details { get; set; } //Other properties here.. [Required] public virtual Employee { get; set; } } Basically I am just getting the existing Employee record then declare it on my property, then add the the Tracking

Confuse about tracking in EF (updating entity with child collection)

半世苍凉 提交于 2019-12-10 18:00:07
问题 So I'm new to EF (I'm using EF6) and I have problem understanding the concept, I'm trying to update entity with child collection. Here's my entity class : public class TimeSheet { public int TimeSheetID { get; set; } public virtual ICollection<TimeSheetDetail> Details { get; set; } } public class TimeSheetDetail { public int TimeSheetDetailID { get; set; } public int TimeSheetID { get; set; } public virtual TimeSheet TimeSheet { get; set; } } My update method : public void Update(TimeSheet

Migrate database-first to code-first - switch from publish to migrations

≯℡__Kan透↙ 提交于 2019-12-10 17:57:24
问题 We need to migrate an existing project from database-first to code-first. Each environment (DEV, TEST, PROD) has a slightly different version of the database. The differences are the changes in DEV that may not have been pushed to TEST and PROD. -- We are using Entity Framework 6.1.3. We have a database project that deploys the database. The publish operation compares the database with the project and builds a script to change the database as needed. We have a models project with an edmx

The required property {0} does not exist on the type {1}. Entity framework (model first) when adding FK

我只是一个虾纸丫 提交于 2019-12-10 17:46:30
问题 I am trying to add foreign key to the database and then I am updating the model. After I update the model, the application gives following error: System.Data.Entity.Core.MetadataException was unhandled HResult=-2146232007 Message=Schema specified is not valid. Errors: The relationship 'Accounting.Data.Repository.FK_np_DocumentStatuses_DocumentsTracking_StateId' was not loaded because the type 'Accounting.Data.Repository.DocumentsTracking' is not available. The following information may be

New embedded Firebird, code first, EF6 project results in SerializationException

烈酒焚心 提交于 2019-12-10 17:39:24
问题 I'm trying to set up Firebird with EF6 as an embedded server for a simple app I'm writing but haven't been able to get it to work. I have a CLI project which is the app and the DAL project which is the DB. I added the NuGet packages to both and created a DbContext with a simple entity, and created an initial migration successfully, but when trying to run update-database to execute the migration I received this error in the Package Manager Console: System.Runtime.Serialization

create new controller - error running selected code generator

心不动则不痛 提交于 2019-12-10 17:35:12
问题 I am using Visual Studio Express 2013 for Web (specifically version 12.0.21005.1 REL). This is my first project using VS2013, I've been using VS2012 up until this point. I am attempting to create a new controller in my asp.net MVC application. I am using Entity Framework 5 with code first (.NET 4.5). I want Visual Studio to create the template for me (you know, a controller with views to read/write/delete etc, rather than write the code myself from scratch). However, every time I try to

Interoperate between ASP.NET MVC and Oracle DB (12c)

折月煮酒 提交于 2019-12-10 17:23:06
问题 I do have a serious problems with between Oracle DB and ASP.NET MVC: How to use Oracle DB in Visual Studio? My environment is: Oracle DB (12c) Visual Stdio 2015 Windows 10 with VMware Use ASP.net MVC with Entity Framework to connect Oracle DB Data How can I get ASP.NET MVC (WEBAPI) to work properly with Oracle DB (12c)? 回答1: How do I create ASP.NET MVC with oracle DB, and as following step by step can tell you how to deal with this issue. Step1. Download [ODAC] (http://www.oracle.com

Customize the DbContext Generator

为君一笑 提交于 2019-12-10 16:58:15
问题 For a database first design, creating the EDMX generates the DbContext and the poco model T4 (.tt) template files. I am successfully able to customize the Model.tt file to make it generate POCO classes with Pascal cased class names and property names and also the poco class file names in Pascal case which fits beter with with the coding standards of the rest of my code. The issue I am trying to tackle is, I have to edit the Model.tt files for every EDMX when I create one, rather I am trying

Alter Stored Procedure in DB Migration EF 6 Code First - how to pass through null as default for a parameter

浪尽此生 提交于 2019-12-10 16:28:58
问题 I am using an Empty Migration to update a stored procedure in my database. The stored procedure is a custom stored proc that was added in the intial creation of the database. I have discovered the 'AlterStoredProcedure' method in the DbMigration class and this works to update the stored procedure, however I have to pass through the parameters of the stored procedure and I want to set the default value of a boolean and some ints to null, but I can't seem to get this to work.