entity-framework

Entity Framework deletion of non-null foreign keyed rows

I have a schema similar to the standard Product / OrderDetails / Order setup. I want to delete a single Product and cascade delete all OrderDetails which reference that product. Assuming that I've thought this through from the business rules perspective, what's the most elegant way to handle that with Entity Framework 4? ...

Entity Framework Delete Performance

I have a Concept table of about 1000 rows that I would like to clear out along with all of its descendent rows in the Attribute table (There should only be one attribute row per concept). Calling save changes below takes about 2 minutes, is there any optimization I can do to the code below, or do I need to write a stored prodcedure. p...

ASP.Net Dynamic Data IS showing my primary keys for every table when using Entities

Using a very run-of-the-mill database, with identity int for primary keys, a Dynamic Data Entities Project (EntityFramework) displays the primary key for view and edit. When using Linq to Sql, the primary key fields are not displayed. I would like to hide the primary keys and use Entity Framework (VS 2008, .Net 3.5 sp1). thanks ...

Accessing foreign key value (int) in Entity Framework

Hi there, I just spent the last 3-4 hours trying to retrieve a foreign key value using linq to entities and a stored procedure. Any advice is much appreciated. public JsonResult GetEvents(double? start, double? end) { AnoEntities _dbAno = new AnoEntities(); var events = _dbAno.Events_GetByDateRange(fromDate, toDate...

EF -> WCF -> JSON

I have a Windows Communication Foundation service which queries the Entity Framework and retrieves data in the form of Entity objects. I'd like to serialize these objects to JSON and send them back to the client to be interpreted in Javascript. It seems this is tricky, according posts like these: http://bloggingabout.net/blogs/progr......

EntityFramework - LINQ Join help

Hello, I have following schema: Clients - ClientId Users - UserId Offices - OfficeId ClientOffices - ClientId, OfficeId UserOffices - UserId, OfficeId Bold entities are EntityFramework Entities. Now I need to write a function which accepts UserId and returns a list of Clients - who also belong to the offices to which user belongs. ...

Is it possible to combine two entities with different PKs?

I'm new to the entity framework so hopefully this is a really simple question... Can I combine these two entities? Here is the db... I want the final to be something like this... ...

Entity Framework on a database without foreign keys

Hi, I'm currently working with a large database (approx. 500 tables) all without any foreign keys define. My question is there an easy way to set up the relationships within entity framework (version 1 or 2) without doing it all manually? Also some of the tables have a complex relationship type. For example a customer has a parentID ...

How can I load related objects in EF?

I want to show Categories of Products I test two approaches : 1. public ActionResult Index() { NORTHWNDEntities _db = new NORTHWNDEntities(); IList<ProductViewModel> pList = new List<ProductViewModel>(); foreach (var p in _db.ProductSet.Include("Category")) { ProductViewModel p1 = new Pro...

restrict num of items loaded in navigation property

Hi All, I have the following query in Linq: var query = from question in context.Questions.Include("QAnswers") join answer in context.Answers on question.id equals answer.qst where answer.user == param_userID select question; return query.toList(); The problem is that it doesn't...

Yet again Entity Framework and FK problems.

I have an entity with two fk's. I've been trying to insert a record to the database without success. This are the approaches I've used: valuePaymentBetToAdd.BetType = db.BetTypes.First(betType => betType.Id == valuePaymentBetToAdd.BetType.Id); valuePaymentBetToAdd.Lottery = db.Lotteries.First(lotto => lotto.Id == valuePaymentBe...

Multiple Left Joins against Entity Framework

I've been looking but can't find a solution to this... Here are my Entities... ContentPage (has many ContentPageZones) ContentPageZone (Has One Content) Content I want to query for a ContentPage by ID , and, I want it to contain all related ContentPageZones that are active and that have at least one Content that is active (both have...

Same data being returned by linq for 2 different executions of a stored procedure?

Hello I have a stored procedure that I am calling through Entity Framework. The stored procedure has 2 date parameters. I supply different argument in the 2 times I call the stored procedure. I have verified using SQL Profiler that the stored procedure is being called correctly and returning the correct results. When I call my method...

How do I *not* supply a column for udpate in EF?

I am sure I am not the first one to struggle with this. I am using Entity Framework 1 (VS2008) and one of the columns in the table is ModifiedDate. It has DefaultValue in SQL Server (getdate()); so I would like to leave it the DB to do the generation. However, generated SQL has INSERT (... ModifiedDate) VALUES (... null), and the defau...

Good resources for learning how to use the Entity Framework 4.0?

I am starting a new module on a project and hear the Entity Framework 4.0 is coming along nicely with its POCO support, lazy-loading, and many other great features. The problem I have is trying to find good resources for learning the technology that isn't geared towards version 1.0 I am following Julie Lermans blog where she is working o...

Entity Framewotk Filter query

ClassABC is not a valid metadata type for type filtering operations. Type filtering is only valid on entity types and complex types. .Search(columns_to_search, parseSearchString(SearchValue)) I got above error when i use in my entity framework query. (from cp in ctx.ABCSet select new {...

Create EntitySet from string name?

How would I create a type while knowing just the name of the type in string form example... My aspx contains this and some bindable control <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=MyEntities" DefaultContainerName="MyEntities" EntitySetName="MyData"> </asp:EntityDataSource...

Round trip logging in entity framework

I know this is possible in Linq-to-Sql, is it possible to automatically log all queries made through a particular ObjectContext in entity framework? In particular, I'm interested in the number of queries that are run in the lifetime of the ObjectContext. ...

Entity Framework connection to SQLite database not working after deployment

I changed a dataset based approach to my sqlite database to one using the Entity Framework. I created the entities using Visual studio 2008's wizard and had the connection string stored in the app.config. A client program then communicates through WCF with the database. This works well on the development computer when I host the WCF serv...

Cannot get to ObjectTrackingEnabled linq

Hello I have had a problem where it appeared as though the second execution of a stored procedure was being ignored. The first time I call my stored procedure it found 20 records and extracted information for the date range August 2009. The first line was meter id 233 with a data value 200 I then called the stored procedure and 20 re...