entity-framework

Using Entity Framework as a database design tool?

One thing I like about the Entity Framework v4 is the fact you can design with a "model-first" approach. I'm also a big fan of the Visual Studio Database project for version controlling changes to the database schema. Traditionally I've been using SSMS tool to generate the schema, and then importing that into the database project. In o...

Why would I want to use POCO's?

I currently use the Entity Framework designer to generate my persistance objects and I also user POCO view models for the ASp.NET MVC view. I've read and listened to a lot of people talking about the good support for POCO's in EF4 as well as POCO's in general but I can't seem to work out what advantage, if any I'll get from using them. ...

Entity Framework query

I ran across this code in one of our Entity Framework applications. I know there has to be a better (more efficient) way than the three queries this code executes. Although, I can't quite get the syntax right. (I am still learing Entity Framework myself..) There are two tables involved. This is a simple parent/child relationship. Ther...

Loading Entity from different table in EF4

Lets say I have two entities in my EF model Customer and Address which map to their respective Customer and Address tables in the db. What I'd like to do is load up a Customer and their Address from the db into these entities but from different tables with slightly different schemas. They will then be saved to the Customer and Address ...

How to map an Entity framework model to a table name dynamically

Using a code-first approach I'd like to map a single model to multiple table names dynamically. Currently I can do something like modelBuilder.Entity(Of Person)().MapSingleType().ToTable("Managers") but as the OnModelCreating method is only called once I can't map it to other table names on the fly. In our current LinqToSql version we'r...

Generic Repository Problem EF4 Code First

Hey Folks, I've got a slight problem when using a generic repository with EF4. First let me show you the code I use to access a collection of objects (this is code in the generic reposiroy): public IEnumerable<T> FindAll<T>() where T : class { return ObjectContext.CreateObjectSet<T>(); } Below is an example of this c...

Entity Framework, inheritence and stored procedures

I have tables named Document, SomeOther1Document, SomeOther2Document. Document table contains columns common to the other tables. If I map these tables in the designer and have the other tables inheriting from Document entity, by default It would use Sql queries and Its all good. However, how would i use stored procedure for selecting sa...

can't generate SSDL from SQLC

I can't generate SSDL from SQLCe. --------------------------- Microsoft Visual Studio --------------------------- Could not find the appropriate DbProviderManifest to generate the SSDL. The supplied provider invariant name 'System.Data.SqlServerCe.3.5' is not valid. --------------------------- OK --------------------------- Is it...

How to update an object using Entity Framework

Hi, I am able to add data, but not sure how should I update the data. I am getting AddObject,DeleteObject methods not found any method to update. Thanks ...

How to create and store a (self-tracking) entity object on the server side?

Hi everyone, I am trying to achieve the following using Entity framework 4.0 and self-tracking entities: 1) The client application request a book form the server by providing an ISBN number 2) The server performs a query on its database to see if the book is already present 3a) If the book is in the database, it returns it. 3b) If t...

Generic repository select by ID in EF4

So I'm trying to create a generic select by ID method for a base repository class. In order to achieve this I'm using EF4 with POCO's. I created an interface with a getter called Id and successfully modified the T4 template in order to have a generic Id property in all the entities that returns the PK. The problem comes when I use the q...

Entity Framework Foreign Key Issue

I am getting a very frustrating issue: System.Data.UpdateException was unhandled by user code Message="Entities in 'MyProjectEntities.GroupingData' participate in the 'FK_GroupingData_AuditTrail' relationship. 0 related 'AuditTrail' were found. 1 'AuditTrail' is expected." This happens when I try to add an object to the data...

One Entity for multiple similar tables

have two tables in database. They have completely the same columns, only the difference between them - they have different names. Lets say i have TableSea with column s Id and Name and TableOcean with the same columns Id and Name. I want to use EF 4 to be able CRUD operations, i am also want to use stored procs mapping for insert upda...

Reformulating EF4 query to avoid parsing error?

How can I reformulate an Entity Data Model query to work around a parsing error? Here is the query: var selectedNotes = notes .Where(n => n.Tags.Count == 0) And here is the exception that is being thrown: There was an error parsing the query. [ Token line number = 12,Token line offset = 53,Token in error = AS ] Here is ...

Does saveChanges method of ObjectContext is wrapped in transaction?

Does anybody know if the saveChanges method sends the SQL script that is wrapped into transaction? thanks in advance. ...

Stored procedure call is very slow from Entity Framework 4 due to inexplicable reason

Stored procedure (query ) when run in Management Studio takes 4-8 seconds. However, when launched inside WCF service via Entity Framework it may take more than minute. WCF runs in VS 2010 in debugging mode with ASP.Net Development Web Server. The actual call requests = transactionEntities.spRequestsForRescreening(cutoffDate).ToArray(...

This method is not supported against a materialized query result

Take a look at my code here: public static ItemType GetItem(int id) { ItemType it = new ItemType(); using (var context = matrix2.matrix2core.DataAccess.Connection.GetContext()) { var q = (from ci in context.Item where ci.ID == id let TemplateID = ci.Templa...

How to substitute the EntityObject with custom class derived from EntityObject?

How to substitute the EntityObject with custom class derived from EntityObject? I'm using default code generation. thanks in advance. ...

How to implement and bind crosstab data using Entity Framework/Winforms?

Hi, I want to keep some timesries data in my database. Raw data are something like below: Time Col1 Col2 Col3 8:00 12 18 20 8:30 14 12 13 9:00 17 15 14 Where number of columns and time steps are undetermined. So I created three tables like this: TimeStamp(ID,Time) Columns(ID,Name) Values(ID,TimeStampID,Colum...

Automapper : mapping issue with inheritance and abstract base class on collections with Entity Framework 4 Proxy Pocos

I am having an issue using AutoMapper (which is an excellent technology) to map a business object to a DTO where I have inheritance off of an abstract base class within a collection. Here are my objects: abstract class Payment class CashPayment : Payment class CreditCardPayment : Payment I also have an invoice object which contains a...