entity-framework

Layered Architecture in Entity Framework 4.0

Hi I am trying architect a small project. I planning to have Data acess, Business Service, WcfService, UI Layer. I am trying to use EF 4.0 and MVC 2.0. My question is where to generate the entities and ObjectContext through EF. I initially planned it in DataAccess. but to make entities available across all layer I have to reference ...

Arithmetic operations on subqueries using Expression.Subtract(?)

I'm trying to create an expression tree that's similar to performing subqueries like: SELECT (SELECT Sum(Foo) FROM Bar1) - (SELECT Sum(Foo) FROM Bar2)) I'm trying to reuse 2 expression trees that are too complex to repeat. What I have right now is 2 (simplified) expression trees: Expression<Func<Bar, int>> SumBar1 = (bar) => (fr...

can wcf service be loosely decoupled

To start with, I am a newbie in the world of WCF so pardon me if this sounds naive. To my understanding , unlike ASP.NET based websites which use ADO.NET to communicate to the database, a silverlight based app always needs a WCF or RIA services to communicate to DB. We know that ASP.NET websites are not tightly coupled to the database ...

Entity Framework -- How to set properties to special types

Hi All, I'm new to MVC and Entity Framework, so this may be a relatively simple answer, but I've tried searching around so far and no luck. I'm using the most recent versions of both tools to my knowledge (MVC 3 Beta and Entity Framework 4.0) I'm just trying to set up a quick example. Logically, I'm dealing with events -- in this case...

Get Last ID From The table [ Entity Framework ]

Could someone guide me on this. I am using EntityFramwork4 , I want to get the ID of the last row of a table. Could someone having experience using this tell me , how can i get the last id from a database table. ...

local database synchronization between sql server database and local sql ce database

Hi, Im implementing application in which there is local database which uses SQL CE. Each time app starts there has to be synchronization between local database and server database (to have new values in dictionary tables). Problem is that mappings are different in sql ce and sql server 2008 when using entity framework. Is it common pr...

Regenerate an EDM with the same name as the one deleted

I have a WinForms application. I created an EDM from my database and called it Foo. Then, I deleted the model. Now, when I try to regenerate the same EDM again from the same database, it doesn't allow me to name the newly generated model Foo. It says that the name Foo conflicts with a property in the application's settings. I poked aro...

Using .Include() when joining a view using Entity Framework

Im using an Indexed View which is an entity without any relations (relations to my table entities would be preferable but this seemed to be nearly impossible to achieve). This view consists of 4 FK's which together form the PK: PortalID CategoryID BranchID CompanyID Now im joining this view to select a set of companies like this: var...

The underlying provider failed on Commit.

Hello, In my mvc asp.net application, I have various modules in that I have insert and edit functionality . Some time I am getting this error: at System.Data.EntityClient.EntityTransaction.Commit() at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) at System.Data.Objects.ObjectContext.SaveChanges() at admin.chamb...

Entity Framework. View return duplicate records

I use Entity Framework that contain view. And I have query: var data = this.context.vwRevenues .Where(x => x.revenue >= 0); .OrderByDescending(x => x.year) .ThenByDescending(x => x.month) .Take(10) .ToList(); This query return set of entities, but 1st entity equals 5th. data[0] == data[4] // true I take sql scr...

Entity Framework 4 generated queries are joining full tables

Hello, I have two entities: Master and Details. When I query them, the resulting query to database is: SELECT [Extent2]."needed columns listed here", [Extent1]."needed columns listed here" FROM (SELECT * [Details]."all columns listed here"... FROM [dbo].[Details] AS [Details]) AS [Extent1] LEFT OUTER JOIN [dbo].[Master] AS [Extent...

Linq to EF Search for a string that does not start with a Letter

I am using Linq to Entity Framework 4, what I'm trying to do is build a query that finds all supplier entities that do not start with a letter, typically these are numbers, e.g. "1st Choice" I thought this would be trivial and wrote this: var letters = Enumerable.Range('A', 26).Select(x => (char)x); var results = from supplier in All() ...

Get TraceString for your business objects in the Entity Framework

How do I get the trace string for a query like this: var product = _context.Products.Where( p => p.Category == "Windows" ) .SingleOrDefault(); // I can't do this since product is not an ObjectQuery instance // product.ToTraceString(); ...

Delete an entity with referential integrity constraints

Let's say you have the following tables: Friend ------ Id int not null (primary key) Name nvarchar(50) not null Address ------- Id int not null (primary key) FriendId int not null (links to Friend.Id) City nvarchar(50) null Country nvarchar(50) not null Using Entity Framework 4, I am issuing an ObjectContext.ExecuteStoreCommand call ...

Entity Framework won't save relations

Hi I have the following situation: role.Permissions.Add(permission); objectContext.SaveChanges(); When I now take a look in the relations table Roles_Permissions the newly added permission to the role is not present. It only saves the new relation when I dispose the object context. Am I doing something wrong or does a call to SaveCha...

How to sort inner list that is returned by entity framework?

How do I sort the inner collection of an object returned by the entity framework? public class X { public string Field {get; set;} public EntityCollection<Y> Ys {get; set;} } public class Y { public string Field {get; set;} } from x in entities.Xs orderby x.Field select x Is there a way to modify this LINQ query to return t...

Entity framework: detaching but keeping object graph

Hi, I'm working in a disconnected scenario, but I noticed that disposing an object context does not release attached entities. As a result, subsequent operations often fail because of this. So to solve this, I detach everything myself when the object context is being disposed: public void Dispose() { // detaching is not really need...

Is it possible to use existing classes as POCOs in Entity Framework

Hi, I was able to generate pocos using POCO template from Microsoft. It works great. My question is how I could modify this or any other template to use existing objects from a different assembly, and just load data into them. The way i tried going about it, was to create POCO's using the template, and the PocoGenerator.Context to ...

Why doesn't Entity Framework easily allow a custom base class?

Is this a design choice by Microsoft, or is there a way to do it, that I'm not aware of? ...

What are each of the template types intended usage, pros and cons?

I have not hardly touched EF4, but I've used Linq to sql quite a lot. I would like to start into one of the EF templates but I have no idea what situations make sense for each or what their intent was. I have the following possibilities: Data templates ADO.NET Entity Data Model Service-based Database (is this even related to EF? Cod...