entity-framework-4

How do entity self-tracking with changes in VM and UI?

my context: Entity Framework 4.0 + WCF Ria Data Service + Silverlight 4. Suppose I have entity People from EF, then I created PeopleVM like: public class PeopleViewModel : ViewModelBase { public PeopleViewModel(){ //.... this._hasChanges = MyDomainContext.HasChanges; } private People _Peopl...

Entity Framework CTP4 Code First: Mapping protected properties

I would like to use a lazy-loading collection on a model, but I want Add/Remove functionality to be done through separate methods. So something like this: class Model { protected virtual ICollection<Something> _somethings { get; set; } public IEnumerable<Something> Somethings { get { return _somethings; } } public vo...

EF4 Code First: Lazy Loading Issue

On the web site I am currently working on I decided to give EF4 Code First a shot. It doesn't seem to bad, although not supporting enums means the impressive points are negated by a simple short coming. Anyway, the problem I have now is that I have a book object which has a collection of authors. When I click on a page where the book is...

Entity Framework - Inserting records in child table when parent record already exists

Good afternoon- I am developing a Silverlight application using LINQ to Entity Framework for the data access layer. My n-tier database model includes about 30 or so tables, with a number of multi-leveled parent-child relationships throughout. Recently began writing my data services and unit tests and have discovered a problem with the...

Entity Framework filter nav property with Self Tracking Entities

I'm using Self Tracking Entities and have a scenario where I have an entity that represents a table that we'll call table A. A is a parent to another table B which is also represented as an entity. On my WinForm I have 3 different binding sources that each represent different types of records from table B but all are children of table A....

EF4 Code only maping inheritance

Hi all, I've got the following model and I want ShiftRequest and MissionRequest to have a single table in the DB. public class RequestBase { public int Id { get; set; } public DateTime? RequestDate { get; set; } public int UserId { get; set; } public virtual ICollection<Notification> Notificatio...

See SQL From EntityFramework with Collection-like Queries

I do not have 'full' the version of MS SQL (SQL Express 2008) so I do not have the profiler tool. I want to see the SQL generated by my Entity Framework code, but all of the examples I find use the var x = from u in table select u; type of syntax; But most of my queries are more like .. var x = context.Users.Single(n => n....

Can this be done with Entity Framework 4 ? If not, what can do this?

Hi folks, I'm making a simplistic trivial pursuit game. I'm not sure if (and then how) I can do the following with EF4 :- I have a table structure as follows. Table: TrivialPursuitQuestion => ID => Unique Question => AnswerId => AnswerType (ie. Geography, Entertainment, etc). Table: GeographyAnswer => ID => Place Name => LatLong ...

Ordering Entity Framework sub-items for EditorFor

I've seen http://stackoverflow.com/questions/3565249/ordering-sub-items-within-ordered-items-in-a-linq-to-entities-query which suggests that there is no way of getting the repository to return sub-items in an entity graph in a specific order. If that's right, any thoughts on how to order the items in an EditorFor ? i.e. //This works ...

Entity Framework function import: input parameters mapping

Hi everybody, Entity Framework allows to map the result of a stored procedure to an Entity easily. What I need is to map an Entity to input parameters, so that instead of context.SaveUser( user.FirstName, user.LastName, ... ); I can simply call it like this: context.SaveUser( user ); What I really want is to isolate possible schem...

Update model from database without system tables?

Is there any option that allows to ignore sys tables when updating model from database? In my case I always have sysdiagram entity and related objectset. thanks in advance. ...

Entity Framework - An item with the same key has already been added. - Error when trying to define foreign key relationship

I have an entity with a foreign key relationship to an asp.net membership provider users table. This portion of the model looks like this: I can't seem to assign the foreign key relationship when inserting the Users table record, the record containing the foreign key to the aspnet_Users table. I keep getting the error: An item w...

How not persist property EF4 code first?

How do I make non persisted properties using codefirst EF4? MS says there is a StoreIgnore Attribute, but I cannot find it. http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx Is there a way to set this up using EntityConfiguration? ...

Entity Framework 4: Eager Loading (Include) with filters using Self Tracking Entities

I have a solution where I have created self tracking entities using the RTM templates. I have split the entities and context between 2 projects so that I can reuse the type definitions as I plan to run client/server via WCF. One of my service methods is required to return a graph of "Product" objects with child objects of "ProductSku" a...

How map objects to a view with EF 4 code first?

How can you map an entity to a database view with EF 4 code first? Is there a way to do this by deriving from the EntityConfiguration classes? ...

Database design w/Entity Framework 4 - where should I put my foreign keys?

I'm developing a couple of media (video games, TV shows, movies) review sites and am having an issue designing the relationships between my data. Case in point: I decided that having a base Content table would be a good idea for most of the data. My Articles, News, and Reviews tables could all point to the Content table. My current s...

Does EF have ordered collections? The equvilant of list in the NHiberante Bag Vs Set Vs List world

Does the Entity Framework 4 have ordered collections? For example my Order has a property that is a collection of OrderItems, but the order is important and I would rather not sort them before I access them. See Nhibernate for an example: http://stackoverflow.com/questions/1916350/set-bag-and-list-set-in-nhibernate ...

Entity Framework 4 - How to Read Multiple Record Sets From A Stored Procedure?

Hi Guys, I have a very simple stored procedure which returns multiple record sets. All of the record sets have aliased columns so they all look the same. E.g. SELECT TOP 10 FooId AS Id, Name As Name FROM Foos SELECT TOP 10 BarId AS Id, Name As Name FROM Bars ... For my EF setup, i'm using POCOs and have my own DataC...

The model backing the <Database> context has changed since the database was created.

The error message :- "The model backing the 'AddressBook' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the RecreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, a...

Entity Framework - CTP4 - Code First - How to turn off the automatic pluralization?

My entity name is "Contact" and my table name is "Contact". However, the default pluralization support is making EF4 to look for a table named "Contacts". Anybody has any idea on how to turn off the pluralization support? This post has got some details on pluralization support. But still does not give me an answer. I see the following...