entity-framework

Generate Database / Entity Data Model from C# Classes

I have been using Subsonic with MVC.NET and love the feature that allows me to generate a database from the c# classes. This is great because it allows you to think about the app first and the data second. Now that I am moving onto MVC.NET 2.0 - I am using the features in the Entity Framework which are great giving form validation clien...

Entity Framework: How can I tell what version I am using?

I believe there are two versions 1 and 2? And version 2 is referred to as Entity Framework 4.0? How can I tell what version is being used in an application? This is in my web.config does this mean I am using version 2? <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> ...

Making Entity Framework 4.0 create POCOs

When I create Entities within the Graphical view of the edmx file. All my entity classes are bundled together in the Designer file. Is there a way to make Entity Framework to create classes in separate files allowing me to have more control over my entity classes? ...

Entity Framework 4 (Linq query doesn't return my roles)

I am currently working on my own version of membership using Entity Framework 4.0 and POCO. After readying Scotts Gu blog post I decided to use conventions as much as possible. So far I have a class called User: public class User { [System.ComponentModel.DataAnnotations.Key] public int UserId { get; set; } [System.Compone...

Is it bad practice to add functionality to EF entities using partial classes?

I'm building a small timing application using the MVVM pattern, using entity framework for persistence. At this stage, my logic is pretty thin, as I only need to perform a few calculations and aggregations on related data. At the moment, I have implemented these by writing them in a partial class of the entity class. For example: // en...

How to create a static UnitOfWork for entity framework 4?

Considering this class public class XQueries { public IQueryable Query1() { using (XEntities context = new XEntities()) { return something; } } public IQueryable Query2() { using (XEntities context = new XEntities()) { return somethingElse; } ...

Entity framework and inheritance: NotSupportedException

I'm getting System.NotSupportedException: All objects in the EntitySet 'Entities.Message' must have unique primary keys. However, an instance of type 'Model.Message' and an instance of type 'Model.Comment' both have the same primary key value but I have no idea what this means. Using EF4, I have a bunch of entities of ...

Can I force multiplicity/assocations with Entity Framework?

I have the following table structure that Entity Framework is correctly returning as a one-to-many: Patient { PatientId PK } Death { DeathId PK PatientId FK } Unfortunately this DB design is wrong as you can only have one Death per Patient. The design should of been like this instead: Death { PatientId PK } However, th...

Entity framework 4 POCO how to update an entity?

This is a method for add/update an entity using Self Tracking Entities, what is the equivalent using POCO? public Hero SaveHero(Hero hero) { using (WarEntities model = new WarEntities()) { if (hero.ChangeTracker.State == ObjectState.Added) { mode...

SQL Server: What would be the appropriate way to define the relationships (borders) between states?

Suppose you have to build a DB tables that depicts states and their borders between each other. Let's say the States table would look like: States: Name(PK), Size, etc... What would be the appropriate way to define the relationships (borders) between states? I came up with three alternatives - Defining a Borders table with primary k...

How do you re-use select statements with Entity Framework?

Given the following query: var query = from item in context.Users // Users if of type TblUser select new User() // User is the domain class model { ID = item.Username, Username = item.Username }; How can I re-use the select part of the statement in other quer...

Exception when databinding a recently created Entity Framework object.

This possibly could be un-related to databinding or entity framework. But this is the scenario my problem is occurring in. This is my code, saving a new entity and then re-binding: Run run = new Run(); run.Distance = 111; rc.RunSet.AddObject(run); rc.SaveChanges(); GridViewRuns.DataSource = rc.RunSet.ToList(); GridViewRuns.DataBind()...

Determining what elements a relationship belongs to when it's being deleted in Entity Framework

Understandably, when I delete a relationship, ObjectStateManager.GetObjectStateEntries(Modified) doesn't say anything about the entity that the relationship belongs to. Since my relationship is a many-many, it does tell me that a relationship is being deleted -- which is nice, but the problem is that I can't figure out which to elements...

how to extend entity framework ,To achieve this effect

how to extend entity framework ,To achieve this effect db.Users.Delete(o=>o.sex=="girl") db.Users.Update(o=>o.sex="girl") Can batch modification and deletion, insert data 怎样扩展entity framework ,可以实现批量修改、删除和插入数据 ...

Performance of returning entire tables containing blog text as opposed to selecting specific columns

I think this is a pretty common scenario: I have a webpage that's returning links and excerpts to the 10 most recent blog entries. If I just queried the entire table, I could use my ORM mapped object, but I'd be downloading all the blog text. If I restricted the query to just the columns that I need, I'd be defining another class that'...

Unable to use a Stored Procedure with my Entity Framework v4 + POCO's :(

Hi folks, I've got a very simple Entity Framework project with POCO Entities. I've got a single stored procedure which I have imported using the EF Wizard. Kewl. I've then made my own EF Entity which I've then Add Function Import to map the Stored Procedure to my EF Entity. Now ... I'm not sure how to map my EF Entity to a POCO. As su...

Possible to use the Repository Pattern + Stored Procedures ? Should / can they return IQueryable?

Hi folks, I'm a big fan of using the Repository pattern to return IQueryable<T> objects. I then let my services layer determine what does what (eg. filter by XXX, order by YYY, project into ABCD, etc). But I've got some hardcore DB stuff, so I've got it all wrapped up into a Stored Procedure. Works fine. I know EF can execute stored pr...

Is there a way to cast ObjectSet<table1> to ObjectSet<EntityObject>?

Hi, I'm trying to make long codes short. The original codes does something following: using (var context = new DataEntities()) { context.Table1.Foreach(x =>{ // Omit ... updating UI DoSomething(x); // Omit ... updating UI }); context.Table2.Foreach(x => { // Omit ... updating UI DoSomething(x); ...

should I move on to entity framework

I use visual studio 2005 , but recently I've heard that there is a new technology which called entity framework .. should I move on and use it instead of using the usual SqlDataReader !! the most important thing to me is the performance , note that I get the data from the DB using DataReader and return it as a generic List .. any su...

How can I enable caching in an EntityDataSource control?

I have three dropdowns, which are bound to the same EntityDataSource control. This results in three identical queries of my database for the data. I have looked for some way to enable caching on the EntityDataSource control, but it doesn't seem to be there? Am I missing something? Am I going to have to roll my own databinding instead...