ef-code-first

Entity Framework Code First - Foreign Key to non primary key field

限于喜欢 提交于 2019-12-13 12:08:07
问题 I have two tables that look like this: dbo.ReviewType ReviewTypeId INT PRIMARY KEY ShortName CHAR(1) - Unique Index Description dbo.Review ReviewId INT PRIMARY KEY ReviewType_ShortName CHAR(1) - FK to ReviewType ... A Review always has a ReviewType. A ReviewType can be associated with many reviews. I'm having trouble mapping this in Entity Framework using the Code First Fluent API. It seems like it does not like me using a foreign key that doesn't map to the Primary Key. I'm using a foreign

EntityFramework pence to pounds

喜欢而已 提交于 2019-12-13 10:27:19
问题 I'm building a WPF application. I made my database using Code-First. I need to insert prices of items in pence (e.g. 500), but when prices will be displayed they should be in pounds (5,00). I tried to do the "conversion" in the setter of my property public decimal Price { get { return price; } set { price = value/100 ;} } But, for some reason, when I drop manually the database, the values in my ListView are shown some times like 0,05 and other times like 500,00. Something must be wrong with

Asp.Net Boilerplate… How to update a record in Existing tables in Database using Async methods?

社会主义新天地 提交于 2019-12-13 10:07:27
问题 I am working with ASP.Net Boilerplate . I want to send isActive=true to the AbpUser table when a user is confirmed by email. How can I access the database and do a query on that? As you know Boilerplate doesn't provide entity classes so I am working with extensions on those classes. I don't know how queries on those classes access the database. Any idea? 回答1: I wrote a sample code to show you how you can update a field of user with IRepository. public interface IUserAppService:

Seeding data will not work when schema changes with Code First when using migrations

我是研究僧i 提交于 2019-12-13 08:53:21
问题 Okay so I am using Entity Framework 6.1 and attempting code first with seeding. I have a drop always intializer that ALWAYS WORKS. However I want to use database migration which I have set up and it works. UNTIL I normalize out a table and then try to seed it I get a primary key error. Basically in my context when I uncomment out the changes in the 'TODO' section and the schema changes I get a primary key violation when attempting population of the newly normalized out table. It will work for

Mvc 3 Scaffolding: the Model passed to the View throws SQL errror

只谈情不闲聊 提交于 2019-12-13 08:41:33
问题 This post has been heavily edited and updated! The Intent: I am writing an app that is essentially a mini ASP.NET MVC 3 accounting package. I am doing it to learn EF 4.1 Code First and Scaffolding The Setup: I am using SQL Server 2008 Express, Visual Studio 2010 SP1 and ASP.NET MVC 3 with Mvc Scaffolding 1.0.2. I have an existing database. The database has the following tables: Accounts Banks CostCentres Currencies DebitCredits People Transactions TransactionTypes There are a number of

EF6 One to Many and Many to One between same entities

♀尐吖头ヾ 提交于 2019-12-13 07:57:27
问题 I'm trying to create a double relationship. Lets say its a Team and Players - a Team has many Players but only one captain public class Team { public int Id { get; set; } public virtual ICollection<Player> Players { get; set; } public Player Captain { get; set; } public int CaptainId { get; set; } } public class Player { public int Id { get; set; } public string Name { get; set; } [InverseProperty("Players")] public virtual Team Team { get; set; } public int TeamId { get; set; } } When

with ef 4.1 code first how can i create a nullable column

馋奶兔 提交于 2019-12-13 07:42:52
问题 I have the following POCO: Public Class T1 <Required()> <MaxLength(128)> <Key(), Column(Order:=0)> Property K1 As String <Required()> <MaxLength(128)> <Key(), Column(Order:=1)> Property K2 As String <Required()> Property C1 As String Property C2 As String end Class I would expect C2 to be created as Nullable, but both C1 and C2 are Not Null. Adding <Required(AllowEmptyStrings:=True)> Does not make a difference, as it seems the decoration is aimed at data validation, not DB creation. So how do

EF 4.1 Code First MVC3 App and Facebook Share Feature

≯℡__Kan透↙ 提交于 2019-12-13 07:28:54
问题 I am working on a simple web application made using Entity Framework 4.1 Code First approach and MVC3. The web application is a simple Quotes website, and on its homepage, the user get a list of quotes. What I would like to do is have a Facebook Share button, like so: And when a user clicks that button, I want the Quote author image, along with his quote and his name to be posted on the user's Facebook wall . I believe they call this Share Functionality. 回答1: Sharing Rich Media https:/

EF Applies All Migrations, Not Just New One

只谈情不闲聊 提交于 2019-12-13 07:22:31
问题 I'm using EF 6 and when I run Update-Database it is trying to apply every migration since the beginning of the project, even though there is only migration that is new. If I attempt to create an empty migration, I get an error that says I can't create a new migration because there are explicit migrations pending. The only blog post I found with a similar issue suggested dropping the __MigrationHistory table and doing Update-Database -Script , stripping out all the actual DB changes but

Entity Framework Code First - How do I tell my app to NOW use the production database once development is complete instead of creating a local db?

点点圈 提交于 2019-12-13 07:20:27
问题 I'm using Code First with Entity Framework 5 using MVC4 and MVC Scaffolding (link/tutorial: http://www.codeproject.com/Articles/468777/Code-First-with-Entity-Framework-5-using-MVC4-and?msg=4531106#xx4531106xx) to create my database from my models. So, basically, when I run the app, the app drops and creates a new database if my model changes. That's great. Now, obviously, this is great for local development. But what about when my app goes to production? How do I tell the code to NOT do this