entity-framework

Extended properties with Entity Framework or NHibernate

Hello, everyone! Is there are an easy way to store some of entitie's properties in a column as a bulk, as XML or something? Querieng by those properties of course is not an option, but it still'd be valuble to be able to extend data model without database migration. ...

MVC ASP.NET, ObjectContext and Ajax. Weird Behaviour

Hi, i've been creating a web application in mvc asp.net. I have three different project/solutions: One solution contains the model in EF (DAL) and all the methods to add, update, delete and query the objects in the model, the objectcontext is managed here in a per request basis. Other solution contains a content management system in w...

Is it possible to store ObjectContext on the client when using WCF and Entity Framework?

Hello, I have a WCF service which performs CRUD operation on my data model: Add, Get, Update and Delete. And I'm using Entity Framework for my data model. On the other side there is a client application which calls methods of the WCF service. For example I have a Customer class: [DataContract] public class Customer { public Guid C...

Is looping through the entityreference the correct way?

I want to get all users that have a specific role to a list of usernames. Is using .Include to include all the users, and going through the UsersReference the best way to loop through all the users that are associated with the role? I noticed I could not do a foreach(User user in role.Users) but UsersReference seem to work, but is that...

Entity Framework naming conventions for many-to-many link tables

Hi, We are designing a SQL Server database with link tables for many-to-many relations. The question is are there any best practices for naming these kinds of tables for use with the entity framework? Let's say there's a table Customer and Address Then there is a link table between them, what do we call it? CustomerAddress ? Or some...

Does this MSDN article violate MVVM?

This may be old news but back in March 2009, this article, “Model-View-ViewModel In Silverlight 2 Apps,” has a code sample that includes DataServiceEntityBase: // COPIED FROM SILVERLIGHTCONTRIB Project for simplicity /// <summary> /// Base class for DataService Data Contract classes to implement /// base functionality that is needed l...

How to use multiple DisplayName attribute using Entity Framework and ASP.Net Mvc 2

Depending on where I use my Class, I want to be able to show a different DisplayName. I have the following class: [MetadataType(typeof(PortalMetaData))] [System.Web.Mvc.Bind(Exclude = "PortalId")] public partial class Portal { public Portal() { this.Created = DateTime.Now; } } public class PortalMetaData { [Requir...

Weird - "The EntityReference object could not be serialized" when serializing from an ASP.NET Web Site, but works OK on an ASP.NET Web Application

I have an Entity Framework data model. Part of the model is a Customer entity. The web service provides a method to get a customer, and to receive an updated version of this customer to be persisted. To test this, I created a new ASP.NET web Application, (Solution > Add > New Project > ASP.NET Web Application), then added a reference ...

Limit child rows in Entity Framework Query

If I have a parent and child modelled relationship. How to I select the parent, and some of the child rows. I cannot seem to do it, and load the parent object. var query = ( from parent in Parents.Include("Children") from child in parent.Children where child.Date == parent.Children.Max(x => x.Date) se...

linq null refactoring code

i have code public List<Files> List(int? menuId) { if (menuId == null) { return _dataContext.Files.ToList(); } else { return _dataContext.Files.Where(f => f.Menu.MenuId == menuId).ToList(); } } is it possible to make it only one line like return _dataContext.Files.Where(f => f.Menu.MenuId == men...

RIA Services Repository Save does not work!?

Hello everybody! Doing my first SL4 MVVM RIA based application and i ran into the following situation: updating a record (EF4,NO-POCOS!!) in the SL-client seems to take place, but values in the dbms are unchanged. Debugging with Fiddler the message on save is (amongst others): EntityActions.nil� b9http://schemas.microsoft.com/2003/1...

Selective eager loading in Entity Framework

Hello, Is it possible to limit the number of associated entities eagerly loaded with Include? e.g. I have Author and Book entities with a many-to-one relation I'd like to load all authors and their last book Thanks. ...

How to force Entity Framework not to lock the database

Hi All, I'm using EF4 and .Net 4 to load some XML from a file into a database. I have a class the wraps around the ObjectContext and has methods that add the marshalled objects from the XML file to the various EntityCollections that represent my tables. Each XML file contains around 200,000 objects on average, the wrapper class create...

How do you perform an INSERT against a model using eSQL ?

Hi, I'm attempting to perform a DML operation against an Entity Framework model, specifically, an INSERT operation. My current eSQL string is: INSERT INTO Contact (a, b, c) VALUES (1, 2, 3) However, this triggers a runtime exception stating: The query syntax is not valid. Near identifier 'INTO', line 1, column 8. I'm having troub...

EntityFramework Procedure or function '' expects parameter '', which was not supplied.

I apologise for asking just a basic question, however I cannot find the cause of this error. I am using Entity Framework to execute a Stored Procedure, and I am passing in four parameters, however the SQL Database seems to reject them. Can anyone point me in the right direction? My code: ObjectResult<SearchDirectoryItem> resultList = ...

LINQ to Entity, using a SQL LIKE operator

I have a LINQ to ENTITY query that pulls from a table, but I need to be able to create a "fuzzy" type search. So I need to add a where clause that searches by lastname IF they add the criteria in the search box (Textbox, CAN be blank --- in which case it pulls EVERYTHING). Here is what I have so far: var query = from mem in contex...

Entity Framework query not returning correctly enumerated results.

I have this really strange problem where my entity framework query isn't enumerating correctly. The SQL Server table I'm using has a table with a Sku field, and the column is "distinct". It isn't a key, but it doesn't contain any duplicate values. Using actual SQL with where, distinct and group by cluases I have confirmed this. Howev...

What is the proper way to handle non-tracking self tracking entities?

Self tracking entities. Awesome. Except when you do something like return Db.Users; none of the self-tracking entities are tracking (until, possibly, they are deserialized). Fine. So we have to recognize that there is a possibility that an entity returning to us does not have tracking enabled. Now what??? Things I have tried F...

Entity Framework ObjectSet detach method functionality

Well, first of all I'll explain the whole situation. I have simple POCO domain model which I'm persisting with EF 4.0. For the first time I used only navigation properties and no FK properties. But later due to some binding purposes I decided to add FK properties to my model (Company_ID in the code below). Here are two classes from that ...

linking the EF 4.0 context to the WCF call context

Hello, I would like to create an Entity Framework 4.0 context when a call is received and invoke to save changes when it finish, (something like JPA). I think it is a good idea because I can use the state for all the call, It is short and encapsulate enogh to be threadsafe and long enough for caching calls and the context itself. Any ...