ef-database-first

Cannot update entity framework model

空扰寡人 提交于 2019-12-13 06:41:26
问题 I have spent nearly seven hours to figure this out and couldn't come up with a solution. So here am I, sharing this problem with you. Please note that the following example is a simplification and subset of my original project. I tried to simplify it as much as possible for you. To start, I have two business models: The following EDMX diagram is as follows: I am using MVC 4 and I have a simple page where you can enter home and away team names respectively and a save button to save these teams

Creating a computed property with Entity Framework 6

情到浓时终转凉″ 提交于 2019-12-13 03:22:40
问题 I am using Database First approach and I have created model from a database. Now I have a datagrid view in my Winforms app, that is bound to a binding source. And all that works fine (an appropriate data is shown in datagrid view). Now the problem is, how to add a computed property that consists of two values (already found in db) ? For an example: Lets say that I have a table user (id, username, first_name, last_name, user_type) but I want to have different columns in my bound datagrid view

Why does Database First EF skip mapping some tables?

给你一囗甜甜゛ 提交于 2019-12-12 11:31:02
问题 I'm using Entity Framework 4 and with a Database First binding, and EF is not generating the entities for a few of my tables. I'm not getting any errors, and no matter how many times I select the tables to generate from the "Update Model from Database" popup menu on the design surface, the same tables are still missing from the model. I get no errors in the wizard. They just don't get generated. Any clues? 回答1: EF requires a primary key on the table. EF will not map tables for which it can't

How to update table not imported by EDMX in C# project

只谈情不闲聊 提交于 2019-12-12 05:13:53
问题 I have a SQL database table which joins two other tables. Classes (Table 1), Students (Table 2). The joined table is called StudentClasses looks like: 1 Composite Primary Key made up of 2 columns: StudentID (from Students), ClassID (from Classes) When I add my database to my C# project through ADO.NET EDMX entity framework database first approach, this joined table does not get added as an auto-generated cs class file, I suppose because it is made up of two foreign keys. It does, however, get

ASP.NET MVC, Entity Framework: Generic model-independent controller class implemented with actions

若如初见. 提交于 2019-12-12 04:14:25
问题 I'm trying to implement this kind of mechanizm: Model has bit field: is_active , so I'm using it to toggle visibility on the main form. The action in controler is like: public ActionResult Toggle(int id) { Country country = _db.Countries.Find(id); country.is_active = country.is_active == null ? true : !country.is_active; _db.SaveChanges(); return RedirectToAction("Index"); } I want my admin lookup controllers to derive from that generic class and use the implementation from it for common

MVC 4 and EF6 database first: issue with mapping

ぃ、小莉子 提交于 2019-12-11 13:56:49
问题 I am following along Pro ASP.NET MVC 4 by Adam Freeman on VS 2010 (I downloaded the MVC 4 template online). I have worked with the .edmx file before, but in Chapter 7 he does not do this. I setup a basic connection string with SQL Server in my web.config file within my WebUI project where my controllers and views are located. Also, I listed my Domain classes within my Domain project below. The problem comes when I run the application. The application is not recognizing my table in my database

EF Database First with TPT Inheritance only creates DbSet<T> for base clases

为君一笑 提交于 2019-12-11 12:24:25
问题 I have an EF6.1 EDMX (Database First) model and I am using TPT inheritance for several types (ie. Employee : Person), however, in the generated Model.Context.cs class I only have DbSet<T> classes for my base types and not the inheriting ones. Is there anything that needs to (or can) be done to either the EDMX model or the T4 templates to generate DbSet<T> for the inheriting classes as well? 回答1: You can get the subtypes from the context by context.People.OfType<Employee>() or you can extend

How to combine both of code first and database first approaches

 ̄綄美尐妖づ 提交于 2019-12-11 05:22:14
问题 Let's say I'm a new developer in a company. So there is already an existing database for the project. To work on the project, obviously I need to scaffold the existing database(database first approach), which can generate model classes for me to work on. So I start to work on the project and want to add a new column to a table, so I add a new property on the model class then I want to apply this change in the database. So I switch back to code first approach by adding a new migration and

MVC4 how to load related data without Navigation Properties

﹥>﹥吖頭↗ 提交于 2019-12-11 03:17:15
问题 I an fairly new to MVC, and have created an MVC4 application using EF-database-first. The database does not contain foreign key definitions and I can't add them (I don't own the database). Here are two example classes from the database: public partial class Allocation { public int AllocID { get; set; } public int DeptID { get; set; } public decimal AllocationPercent { get; set; } } public partial class Department { public int DeptID { get; set; } public string DeptName { get; set; } public

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