entity-framework-4

Help me understand entity framework 4 caching for lazy loading

空扰寡人 提交于 2019-12-06 13:54:40
I am getting some unexpected behaviour with entity framework 4.0 and I am hoping someone can help me understand this. I am using the northwind database for the purposes of this question. I am also using the default code generator (not poco or self tracking). I am expecting that anytime I query the context for the framework to only make a round trip if I have not already fetched those objects. I do get this behaviour if I turn off lazy loading. Currently in my application I am breifly turning on lazy loading and then turning it back off so I can get the desired behaviour. That pretty much sucks

EntityFramework : Calling ToList() on IQueryable with ~11.000 records takes 10 seconds

我与影子孤独终老i 提交于 2019-12-06 13:46:11
I want to return a relatively large number of records from SQL Express 2008 R2 server, via EntityFramework 4 through WCF service to a WCF client. My test table contains around 11.000 records at the moment. The LINQ query is as simple as this: Database DB = new Database(); // create object context var retValue = DB.Entities.Persons .Include("District") .Include("District.City") .Include("District.City.State") .Include("Nationality") return retValue.ToList(); This takes about 10 seconds to complete. The same SELECT query takes less than 1 second when executed in SQL Server Managament Studio.

unable to return json data, WCF Resful Service .NET 4.0

谁说胖子不能爱 提交于 2019-12-06 13:41:11
I recently set up a WCF Resful Service with Entity Framework 4.0 It works with XML perfectly, however when I try to return it in json format I got HTTP/1.1 504 Fiddler - Receive Failure Content-Type: text/html Connection: close Timestamp: 01:11:06.453 ReadResponse() failed: The server did not return a response for this request. Any Ideas?? thanks in advance Edit: The Code is quite normal, actually i tried two way of doing it, but no luck. Hard code ResponseFormat Way: [OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json,

Delete entity in EF4 without loading the entire entity

天涯浪子 提交于 2019-12-06 13:03:13
I am using entity framework 4 and have the following setup and problem. I have a table in MySql with metadata fields an a blob field. Using the Table Splitting technique described here i have divided the table into two entities (DataItem and DataItemDetails). This way I can load all the metadata without loading the blobs. Problem is that when I try to delete a dataitem entity I get this exception: exception: System.Data.UpdateException: Invalid data encountered. A required relationship is missing. Examine StateEntries to determine the source of the constraint violation. If I turn of Lazy

Pluggable Conventions in Entity Framework

烂漫一生 提交于 2019-12-06 12:57:38
I am following EF Feature CTP5: Pluggable Conventions to create custom pluggable convention (in this particular case to change the precision of all decimal fields). Looks like in the latest release of EF the Add method on ConventionsConfiguraions is also "internal'. How do i add custom Pluggable Conventions now? The feature has been removed in EF 4.1 and a possible implementation postponed to a later release: Code First customizable (pluggable) conventions are not supported. Removing the default Code First conventions is supported. Quote from here: http://msdn.microsoft.com/en-us/library

how to avoid SQL Injection with Linq with EF in codefirst technique in c#

☆樱花仙子☆ 提交于 2019-12-06 12:29:13
I am using asp.net mvc 3 with WCF with EF 4.1 With Sql Azure. I am building the search engine for my application. and using the dynamic Linq to build queries. I want to avoid the sql injetion in this scenario. what is the best practice for the same ? what are the precaoution i should take in this scenario ? As long as your are building your queries through LINQ, then you are not vulnerable to SQL injection. While this doesn't mean that your code is invulnerable to ALL sorts of attacks (brute forcing passwords, etc.), you won't be vulnerable to SQL injection. Dynamic LINQ automatically protects

Releasing ObjectContext while using StructureMap

蓝咒 提交于 2019-12-06 12:10:21
I've been using StructureMap to inject ObjectContext (entities) into my repositories along with lazy-loaded POCO classes. This is my Structuremap registration. For<WebEntities>().LifecycleIs(new HybridLifecycle()).Use(()=>new WebEntities()); I have defined Partial classes against my POCO classes to retrieve info that is not defined in my EDMX schema. e.g. Community.FloorPlanImages would be a getter which filters only the floor plan images from all available Images. Worked pretty well until I started to optimize my queries. Using EFProf, I found out that none of my connections were being closed

Entity Framework mapping of object containing list of same objects

不羁岁月 提交于 2019-12-06 11:32:58
Currently in my code I am doing something like this public class Subject { private List<Subject> _prerequisites; } A subject can have many prerequisites (which are also subjects), and subject can be a prerequisite of many subjects. We were originally using typed datasets to save the data to the database and our tables looked like this: We now want to migrate from using typed datasets to entity framework but I'm not sure how to create the mapping. Generating the EF from the database doesn't really work as it just drops each table and uses the foreign keys as navigation properties. From what I

Entity Framework get user from contex in saveChanges

a 夏天 提交于 2019-12-06 11:27:13
i have two projects in my solution, UI as mvc and class project for entitiy model code first. I have severall entities in my model but now I need to extend them by new audit fields where I need to save who changed entity. I added new interface public interface IAuditable { /// <summary>Gets or sets the name.</summary> /// <value>The name.</value> DateTime CreatedDate { get; set; } /// <summary>Gets or sets the name.</summary> /// <value>The name.</value> string CreatedBy { get; set; } /// <summary>Gets or sets the name.</summary> /// <value>The name.</value> DateTime UpdatedDate { get; set; }

How do I view an entityset and uncommitted changes?

不想你离开。 提交于 2019-12-06 10:52:21
I'm using EF4 and when debugging, I want to see what changes are about to be made to the database. For example, if I add a bunch of new entities, like contacts, I want to see the list of contacts that will be added when .SaveChanges() executes. Likewise, if deletions will occur, it would be nice to see what will be deleted. Is there a visualizer or similar tool in VS2010 that does this? Thanks! That is not visible directly. The best place is check ObjectStateManager which holds state entries for each entity and independent association. Each ObjectStateEntry representing entity has Entity