entity-framework-6

Code-first migration: How to set default value for new property?

我是研究僧i 提交于 2020-02-12 17:35:21
问题 I am using EF6 for storing instances of the report class in my database. The database already contains data. Say I wanted to add a property to report , public class report { // ... some previous properties // ... new property: public string newProperty{ get; set; } } Now if I go to the package-manager console and execute add-migration Report-added-newProperty update-database I will get a file in the '/Migrations' folder adding a newProperty column to the table. This works fine. However, on

Code-first migration: How to set default value for new property?

与世无争的帅哥 提交于 2020-02-12 17:33:33
问题 I am using EF6 for storing instances of the report class in my database. The database already contains data. Say I wanted to add a property to report , public class report { // ... some previous properties // ... new property: public string newProperty{ get; set; } } Now if I go to the package-manager console and execute add-migration Report-added-newProperty update-database I will get a file in the '/Migrations' folder adding a newProperty column to the table. This works fine. However, on

Code First: Avoid discriminator column and keep inheritance

雨燕双飞 提交于 2020-02-11 18:53:54
问题 In my project I have: public class BaseEntity { [Key] public int Id {get; set; } } Then I have to define 10+ POCO classes to define the tables in my database: public class MyTable : BaseEntity { //define properties here } Of course, because MyTable inherits from BaseEntity I get that Discriminator field. I want to get rid of the Discriminator field as I do not need the table BaseEntity to be created nor I need to implement some sort of inheritance into my database. Is it possible? 回答1: A

Code First: Avoid discriminator column and keep inheritance

天大地大妈咪最大 提交于 2020-02-11 18:53:49
问题 In my project I have: public class BaseEntity { [Key] public int Id {get; set; } } Then I have to define 10+ POCO classes to define the tables in my database: public class MyTable : BaseEntity { //define properties here } Of course, because MyTable inherits from BaseEntity I get that Discriminator field. I want to get rid of the Discriminator field as I do not need the table BaseEntity to be created nor I need to implement some sort of inheritance into my database. Is it possible? 回答1: A

Standardizing and Abstracting IQueryable construction with Linq to Entities

十年热恋 提交于 2020-02-08 05:48:24
问题 TL;DR; What is the best way to standardize and abstract IQueryable construction in large data access layers? Are extensions acceptable or encouraged? Background We're using Entity Framework 6 with a Repository pattern as our Data Access Layer. In order to make our data calls more efficient, we've recently started using some structured Data Transfer Objects to force ourselves to only pull from the database what is necessary. For example: We have a dashboard that uses 15 of 500 properties of an

Building Project that uses EntityFramework fails with a lot of errors

无人久伴 提交于 2020-02-07 17:08:49
问题 I am using EntityFramework as my Data Access Layer in a Visual Studio C# project. I have added a new entity model and built right away without adding or doing anything to test its functionality. Unfortunately, the build failed with many errors like: CS0426 The type name 'Data' does not exist in the type 'System' CS0138 A 'using namespace' directive can only be applied to namespaces; 'System' is a type not a namespace. Consider a 'using static' directive instead CS0246 The type or namespace

Building Project that uses EntityFramework fails with a lot of errors

随声附和 提交于 2020-02-07 17:08:10
问题 I am using EntityFramework as my Data Access Layer in a Visual Studio C# project. I have added a new entity model and built right away without adding or doing anything to test its functionality. Unfortunately, the build failed with many errors like: CS0426 The type name 'Data' does not exist in the type 'System' CS0138 A 'using namespace' directive can only be applied to namespaces; 'System' is a type not a namespace. Consider a 'using static' directive instead CS0246 The type or namespace

Error 3027: No mapping specified for the following EntitySet/AssociationSet

Deadly 提交于 2020-02-03 05:31:05
问题 I am using EntityFramework 6 and I used Update Model from Database after inserting table in the database, I got above error.Please state how to overcome this problem. 回答1: Open the edmx file on notepad, find the unmapping association and remove it. It should work. 回答2: I got the same error and found that the foreign key in the table I had added was not of the same type as in the referenced table. 回答3: Not too satisfying, but I solved it by removing and re-adding the model: Right-click on edmx

Entity Framework 6 Code First migrations - multiple branches for production

一笑奈何 提交于 2020-02-01 15:32:33
问题 In my project we have a branch model that has a separate development branch and has a separate branch for each release. It may look like this: dev ______ ______ / \ / \ master --+---+----+---+---+----+----+--- (...) r1 \______/ r2 \_______/ So we develop on dev merge it to master and then we create a release branch (r1, r2, ...). We want to use EF 6 (manual not automatic) migrations but we have a question that we don't know how to answer. Imagine this: dev _(1)__ ____(4) / \ / \ master --+---

Entity Framework 6 Code First migrations - multiple branches for production

蹲街弑〆低调 提交于 2020-02-01 15:31:06
问题 In my project we have a branch model that has a separate development branch and has a separate branch for each release. It may look like this: dev ______ ______ / \ / \ master --+---+----+---+---+----+----+--- (...) r1 \______/ r2 \_______/ So we develop on dev merge it to master and then we create a release branch (r1, r2, ...). We want to use EF 6 (manual not automatic) migrations but we have a question that we don't know how to answer. Imagine this: dev _(1)__ ____(4) / \ / \ master --+---