entity-framework-4.1

Problem modelling relationship in Entity Framework using code first

寵の児 提交于 2019-12-01 15:11:17
问题 I'm trying to learn code first within the Entity Framework and am having trouble modelling a relationship. It's a basic HR database which for the sake of this has two entities, Employees and Departments. The Employee belongs to a department and the department has a Team Administrator and a Manager, both of whom are in effect employees. I've tried to model this using the following: EMPLOYEE public int? DepartmentID { get; set; } public virtual Department Department { get; set; } Context:

Error loading EntityFramework 4.3.1

有些话、适合烂在心里 提交于 2019-12-01 14:54:02
问题 I created an MVC application in C#. I created a new project in my solution called PhoneDomain. The purpose of this is to separate my data and domain layer from the actual problem. I right clicked on the project and went to "Add Library Package Reference" and I attempted to add the EntityFramework package (version 4.3.1). It said " Operation Failed " " This package contains an init.ps1 file and needs to be installed from the Package Manager Console ". So I opened the Package Manager Console in

Entity Framework Code First and Collections of Primitive Types

房东的猫 提交于 2019-12-01 14:36:26
问题 When creating POCO classes that contain collections of primitive types and are persisted by EF Code First, the best advice I have found so far is to create a new class that has an ID plus the primitive type: Entity Framework and Models with Simple Arrays If I now have several classes that require properties of type ObservableCollection<string> and replace them with ObservableCollection<EntityString> (where EntityString is a custom type with an Id and a string property), I end up with a table

Entity Framework 4.1 DatabaseGeneratedOption.Identity Performance

元气小坏坏 提交于 2019-12-01 14:30:43
I currently working on a application that use Entity Framework 4.1 (code first) and SQL Server CE 4.0. One of the new things I really like from SQL Server CE 4.0 are the computed values. But I have some performance problem while importing old data into my new data store system (around 50000 entries). This is my second implementation for this. The first version used Entity Framework 4.0 and SQL Server CE 3.5. But there is a huge performance difference between these implementations. The code first implementation takes around one hour to import the entries, the other implementation only some

Entity Framework 4.1 - Relationships between non-key columns

这一生的挚爱 提交于 2019-12-01 14:05:56
问题 I have 2 entities that are related, but the legacy sql schema essentially has 2 key columns for the same table (not a 2-column key: see below). I need to create a relationship back to the 'faux key' column. Is there a way to do this declaratively in Entity Framework 4.1? Public Class Client Inherits ModelBase <Key(), Required()> Public Property ClientID As Decimal <Required(), StringLength(50)> Public Property ClientCode As String ........ Public Class ClientLocation Inherits ModelBase ......

MVC3 Music Store Tutorial Connection String issue

我的梦境 提交于 2019-12-01 12:53:17
I'm working my way through the MVC Music Store Tutorial and am running into an issue when I try to connect to the database using the entity framework model. I've tried a number of these walkthroughs, and I'm continuing to run into problems when I get to this part. I do not want to use SQL Compact Edition (although I've tried to install it just to get the tutorials to work). Rather, I have SQL Server Developer 2005 Edition as well as a named instance of SQL2008 Express (again, installed just to see if I could get the tutorial to work). Here is my connection string: <connectionStrings> <add name

How to manually update Entity framework Code first model so that it updates a database (with a new column)?

不羁岁月 提交于 2019-12-01 11:52:31
问题 can somebody tell me how I can add a data member (col) to my mvc3 model (class) and have it update the database without having to generate everything from scratch? I'm working from code first. When I change my model then run my project I get an error stating that model has changed. Any clean and easy way to synch creating a new col/data mamber with the db/model? Thanks! 回答1: you can use this in application start, Database.SetInitializer(new DropCreateDatabaseIfModelChanges<YourDBContext>());

Cant Add controller which uses Class which is inherited from other class

允我心安 提交于 2019-12-01 11:35:01
I'm using Entity Framework and MVC3, and my problem is that I can't scaffold Controllers if the class inherits from another Class. Example: This is Base Class using System; using System.Collections.Generic; namespace CRMEntities { public partial class Company { public int Id { get; set; } } } This is Lead Class (Child) using System; using System.Collections.Generic; namespace CRMEntities { public partial class Lead : Company { public Lead() { this.Status = 1; this.IsQualified = false; } public Nullable<short> Status { get; set; } public Nullable<bool> IsQualified { get; set; } } } When I tried

How can i made a pivot for this

旧街凉风 提交于 2019-12-01 11:20:37
I have linq that return my data in this format Servicio2 | Indicador | Accion1 Servicio2 | Indicador | Accion2 Servicio1 | Indicador1 | Accion1 Servicio1 | Indicador1 | Accion2 Is there a way to transform the output to this Servicio2 | Indicador | Accion1 , Accion2 Servicio1 | Indicador1 | Accion`, Accion2 Based on this linq from A in db.IndicadorServicioAccion .Include("Accion") .Include("IndicadorServicio") .Include(i => i.IndicadorServicio.Indicador) where A.Usuario.IDUsuario == id && A.Permiso == true select A) UPDATE based on @Aducci answer (from A in db.IndicadorServicioAccion .Include(

EF4.1: Possible to have zero-or-one to zero-or-one (0..1 to 0..1) relationship?

我的梦境 提交于 2019-12-01 10:38:25
.NET 4.0 with SQL Server 2008 R2. I am trying to represent a 0..1 to 0..1 relationship and I keep getting the following error: Error 113: Multiplicity conflicts with the referential constraint in Role '{0}' in relationship '{1}'. Because all of the properties in Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'. I get this message even when the properties in the dependent entity are nullable. Is it possible to represent this relationship in Entity Framework? An example of when this might occur (independently of whether it is good database design to do so) is when