entity-framework

How to apply LINQ to ObjectResult<int?> when using EF 4.0?

Suppose I have a function call from EF like: var result = context.myFunction(); the result type is ObjectResult<int?>. Then I want to use linq to get the single value. How to write the linq? ...

ASP.Net Entity Framework Repository & Linq

My scenario: This is an ASP.NET 4.0 web app programmed via C# I implement a repository pattern. My repositorys all share the same ObjectContext, which is stored in httpContext.Items. Each repository creates a new ObjectSet of type E. Heres some code from my repository: public class Repository<E> : IRepository<E>, IDisposable where...

EF4 and ASP.Net MVC to Test and Develop without mapping to an underlying database (until later)

Hi I want to develop an ASP.Net MVC application with EF4 Model First design and only generate the actual database much later, ideally at the end of the project. Based on some of the ideas here: http://elegantcode.com/2009/12/15/entity-framework-ef4-generic-repository-and-unit-of-work-prototype/ I want to create something like an ...

Entity Framework - avoiding another query

I have a requirement to only save data to a table in a database (I don't need to read it) If the record already exists I want to update it otherwise I will add it. It usually exists. My entity context might already hold the object .. if it does I want to find it and use it again without causing it to refresh from the database when I '...

Entity Framework conversion from v1 to v4 problem

After converting my data access layer project from EntityFramework v1 to v4 a got a bunch of errors for each of the entity classes: Error 10016: Error resolving item 'EntityTypeShape'. The exception message is: 'Unresolved reference 'NS.EntityName1'.'. DataAccessLayer\Model.edmx and Error 10016: Error resolving item 'AssociationCo...

Is it possible to make a non-nullable column nullable when used in a view? (sql server)

Hi, To start off I have two tables, PersonNames and PersonNameVariations. When a name is searched, it finds the closest name to one of the ones available in PersonNames and records it in the PersonNameVariations table if it's not already in there. I am using a stored proc to search the PersonNames for a passed in PersonNameVariationand...

Maintaining state and data context between requests in ASP.NET + EF4

I have a EF4/ASP.NET web application that is structured to use POCOs and generic repositories, based essentially on this excellent article. The application is relatively sophisticated with one page that involves selection and linking of multiple entities to build up a complex user profile. This requires access to multiple entity types (...

Entity framework MappingException: The type 'XXX has been mapped more than once

Hi everyone, I'm using Entity framework in web application. ObjectContext is created per request (using HttpContext), hereby code: string ocKey = "ocm_" + HttpContext.Current.GetHashCode().ToString(); if (!HttpContext.Current.Items.Contains(ocKey)) { HttpContext.Current.Items.Add(ocKey, new ElevationEntityModel(EFConnectionString))...

Best way to attach row from datagrid to EF.

Using MVVM and EF...I have a datagrid binding to a View Model (using ObservableCollection). The view model has a save command which simply calls the SaveChanges command of the Data Context. However, when a user adds a new row to the datagrid, the new entity is detached. Is there any easy way to automatically attach it when it gets cre...

Handling thousands of object in Entity Framework 4 : any grid ?

Hi I have a DB with 50 000 records mapped to EF 4 classes. I have not found any WPF grid capable to correctly handle EF object correctly (lazy loading, filtering....) Does anyone has some experience with such figures with EF ? which grid have you been using ? Thanks Jonathan ...

Dynamic Data - Make Friendly Column Names?

I've created a Dynamic Data project with an Entity Framework model. It works nicely. But, right now it shows all my database tables with the db column names - which aren't always the most friendly (e.g. address_line_1). How can I got about giving these more friendly column titles that will display to the end user? ...

Entity Framework 4 Primary Key as GUID and autogeneration

I'm trying to use EF4 and the supposedly new feature of having GUIDs generated server side. I have a table with a GUID primary key and its default value is set to NewID() in SQL Server. However, I have tried setting StoreGeneratedPattern to Identity and Computer and neither works. I found this link on MSDN, with conflicting informatio...

MySQL Entity Framework and Inhertitance

Does anyone know of a good tutorial demonstrating inheritance in an entity framework model preferably where MySQL is the backend? ...

RIA Services - Two entity models share an entity name

I have two entity models hooked up to two different databases. However, the two databases both have a table named 'brand', for example. As such, there is a naming conflict in my models. Now, I've been able to add a namespace to each model, via Custom Tool Namespace in the model's properties, but the generated code in my Silverlight proje...

Using Structuremap to manage ObjectContext Lifetime in ASP.NET MVC

Hi, what I want to know If there is a way or an good article on how to manage the objectcontext life cycle through structuremap (I saw an example with ninject). Since I'm new to the methods and possibilities of SM I really don't know How/If possible to make it. In the first moment I wanted to make a singleton of the objectcontext per htt...

complus Exception code -532462766

Using visual studio 2010, entity framework 4.0, ADO.NET POCO Entity Generator On the code lines: MecDbEnt.Domains.AddObject(subject); MecDbEnt.SaveChanges(); (on this line) the application throws follow exception: complus exception code -532462766 Does anyone know how to solve an error like this? Thx! ...

Mapping custom POCO in Entity Framework 4

So I have a small issue with converting a string to a boolean when EF maps to my POCO. I created custom POCOs and I have one that has a boolean property called "IsActive". But, in the database the tables column "IsActive", that maps to the POCOs property, is a string. It's either 'Y' or 'N'. EF doesn't like this, so I'm wondering if th...

Is there a way to add extra fields to an association in the ADO.NET Entity Framework?

I would like to be able to model a many-to-many relationship that has extra details about the relationship. For example: Person: int id, String name Project: int id, String name ProjectPerson: Person.id, Project.id, String role Whenever I create the ProjectPerson association in the EF, I am unable to add the role attribute to the as...

Use SmallDateType in Model-First Entity Framework

I can't help but feel I am missing something but to this day I cannot find the answer. I am doing a model-first entity framework and have a few properties set as DateTime. These translate to DateTime in the database - but I would like to use SmallDateTime. In my case, getting down to seconds and milliseconds just isn't worth the doub...

how to select specific number of child entities instead of all in entity framework 3.5?

Hi all, i am wondering how can i select specific number of child objects instead of taking them all with include? lets say i have object 'Group' and i need to select last ten students that joined the group. When i use '.Include("Students"), EF includes all students. I was trying to use Take(10), but i am pretty new to EF and programm...