entity-framework

Entity Framework and Linq to Entities and .Include() few tables, or maybe ..

Hi. i've got a database with a table named PropertyValues where i store every value i need to describe some properties of my database table rows. For example, table Products which looks like this : ID OrderID //Products table is related with Order table ProductName ProductType_ID // ID of PropertyValues table which describes...

Storing Multiple Changes in Entity Framework

Hi there, I'm trying to achieve a form of two phase commit using Entity Framework 1.0. What I would like to achieve at a high level is: get all the data from the database and store this in a cache. modify individual entities Commit all changes into the database The problem's i've encountered so far is that caching an IQueryable ...

Entity framework IQueriable

I'm having problems querying the entity model to get additional information. My db has a Program table with a one to many relation with an Events table. The Entity model generates the relationships just fine, but I'm unable to figure out how to query the model to get the progam object with its events. I can do this: var foo = from pr...

Configuring Entity Framework on a Database Undefined Foreign Key Relationships

For a variety of reasons the database that I'm working on (SQL Server 2005) doesn't have any relationships defined. Every table has a primary key. And most tables have at least one foreign key, however we've never configured the constraints. Can anyone tell me the steps that I should take to inform Entity Framework of the underlying rel...

Entity Framework: Private Setter on an Abstract Class

We have an abstract class where all properties have private setters. In our concrete derived class, the code generator is creating a static “create” method that attempts to set the properties of the abstract class. Obviously this fails since the setters are private. How do we suppress the creation of the “create” method? ...

EF4 - POCO Problem...

I was just trying to do some extensive model first using the self tracking POCO approach. I do however not get it to work as I wish. Let's take a blog. Each blog has a set of Entries and each Entry has a set of Comments. Unfortunately the following Model does not work for me. The POCO class implementation looks like the following: pub...

How to create a LINQ expression from an Entity Framework navigation property?

I have the following bit of code: Expression<Func<Subscription, Service>> service2= subscription => (from relationship in subscription.ChildRelationships select relationship.SecondService).FirstOrDefault(); It creates an expression that I can use later as part of a query with the entity framework. The actual code I'm using has a w...

Can't insert data in a table using entity framework

I'm working with the Entity Framework and I'm having a problem: When I try to insert some data in a table it tells me that it's violating integrity of reference but the other table is normally populated and has the value i'm trying to insert. Pedido pedido = new Pedido(); pedido.Data = DateTime.Now; db.AddToPedido(pedido); db.SaveCha...

Implementing a Search Box using ASP.NET MVC, SQL Server, Entity Framework

I have no experience building a search solution, but I'd like to have a search box within my solution and I don't know where to even begin. Are there cool SQL Server tricks that I can use to make my search solution performant (I'm using a hosted SQL 2008 server) I'd love pointers to a multi-step tutorial that starts me off with a simpl...

Entity Framework Load Error

I have this query this.FixturePartidoPuntaje.Load(); var partidos = from q in this.FixturePartidoPuntaje where ( q.FixturePartido.Equipo.EquipoId.Equals(equipoId) || q.FixturePartido.Equipo1.EquipoId.Equals(equipoId)) && q.puntaje > 0 select q; The most i...

How to create ADO.NET Entity Framework ObjectContext extensions

I'd like to create the context extension methods described in Cesar de la Torre's blog post. But I'm not sure how to declare the class that holds my extension methods. Griff Townsend wrote: If I include a reference to this class (or have the class in my namespace), any ObjectContext references will be able to execute these ex...

Row insertion order entity framework

I'm using a transaction to insert multiple rows in multiple tables. For these rows I would like to add these rows in order. Upon calling SaveChanges all the rows are inserted out of order. When not using a transaction and saving changes after each insertion does keep order, but I really need a transaction for all entries. ...

Is the Entity Framework out yet?

Since LinqToSql has been replaced by the Entity Framework, is the Entity Framework out yet? ...

Is it possible to make an association between a Table and View in Entity Framework?

I have 2 databases (sql server 2005) in my system, one for configuration data and the other one for Application Data, but there are some tables that are needed in both databases. We've solved that using Synonyms but the problem is when we map the tables in Entity Framework. We have a Language table in the config database, used for locali...

Can't insert data in table with relationship (entity framework)

I'm working with the Entity Framework and I'm having a problem: When I try to insert some data in a table it tells me that it's violating integrity of reference but the other table is normally populated and has the value i'm trying to insert. Pedido pedido = new Pedido(); pedido.Data = DateTime.Now; db.AddToPedido(pedido); db.SaveChan...

Strongly-Typed ASP.NET MVC with ADO.NET Entity Framework

I've finally gotten this working after days of struggle. I've got a simple database of People and Departments: I can use strongly-typed ASP.NET MVC views for reference/navigation properties! See the list of departments... Part of my Person/Edit view: <% using (Html.BeginForm()) {%> <%= Html.Hidden("Id", Model.Id) %> <fie...

Handling lookup tables in Entity Framework

I am just getting started with Microsoft's Entity Framework, using it for an MVC project since MS seems to be really pushing it, and I'm running into some issues. In my database there are multiple lookup tables tied to a single table via foreign keys. Within the entity framework I am trying to combine these into one so that I have a simp...

EF4 - custom ObjectContext and inheritance question

Spinning further on the previous question I had. Let's say I inherit BlogEntry and Comment from Post. I now want to customize them a bit. A comment to a blog post does not need a title but a comment needs a user reference so I move these two fields out from Post and into Comment and Blog entry like this: public abstract class Post { ...

How to fake Foreign Key Collections Properties in Entity Framework and ASP.NET MVC

In Alex James' blog post How to fake Foreign Key Properties in .NET 3.5 SP1, he explains how to add a Foreign Key property to an Entity Object. I've used that to get a reference/navigation property working with a DropDownList in a strongly-typed ASP.NET MVC application as explained here: Strongly-Typed ASP.NET MVC with ADO.NET Entity F...

How would you design your database to allow user-defined schema

If you have to create an application like - let's say a blog application, creating the database schema is relatively simple. You have to create some tables, tblPosts, tblAttachments, tblCommets, tblBlaBla… and that's it (ok, i know, that's a bit simplified but you understand what i mean). What if you have an application where you want ...