entity-framework

Error when trying to change the multiplicity of a relationship in EF4

I'm trying to build a relatively simple game review site. There should be a 1-to-1 relationship between games and reviews (each review is for one game, and there will only ever be one review for a game). My tables are pretty simple. The relevant parts are: Reviews Table: ReviewID - int, primary key Text - text GameID - int, foreign k...

Should I switch from Web Services to Entities to do my SQL data manipulation?

I have a number of web application projects in a .net environment that use web services created by my DBA to select, update, and delete data from my SQL database. My DBA suggests that he will continue to create new web service interfaces for new projects in the future. I understand that this process is somewhat inefficient in terms of ...

Dynamically build an expression for calling the LINQ Where method.

I'm using some code from a book to implement a generic repository class for EF data access. the code uses the following two methods to get a single entity by its int id primary key, assuming all DB objects have an int PK. However, I am using an imported DB with mainly natural keys, and I wish to preserve all the FK relationships as the...

Exposing Entity Framework Entities as properties on ViewModel for MVVM Databinding

If I expose my EF 4 Model objects (EF4 entities) as properties on my ViewModel am I "breaking" MVVM ? Do I have to duplicate each Model class as some sort of DTO and expose those DTOs from the ViewModel ? I understand the theoretical value of having the View "not know" about the Model, but the reality is that (if I don't expose the M...

Entity Framework; updating DB from Model?

In mySql Workbench there's a possibility to "sync" the model with the DB and vice versa. Is there a function like this in EF? I've added som entities and I'd like it to get reflected in the DB. Do I really have to regenerate the entire DB and loose data? Thanks ...

Entity Framework unitofwork vs self-tracking entities

This questions stems from a n-tier application. (non-WCF - only separate assemblies) Should I use a unitofwork pattern and keep my object context around for entity change tracking? or Should I use self-tracking entities and always dispose my object context after a query, insert, delete, etc... and have the entities track themselves...

How can I get an IList of entites and their child objects in Entity Framework efficiently?

That is, I want to do this: var lists = (from list in this.DB.Lists select new { List = list, Items = list.ListItems.ToList(), }).ToList(); But, obviously, the Entity Framework doesn't support the ToList extension method in the select clause. What should I do? ...

Entity Framework how to make an EntityObject self-tracking

From what I can tell in order for an object to be self tracking it needs to implement IObjectWithChangeTracker. Entities out of the box (made with EDMX generated code) implement IEntityWithChangeTracker. Is there any way to make a EDMX code generated entity self tracking? Thanks! ...

Entity Framework use model for different providers

I have an entity 4.0 model that is using a SqlServerCE database as its provider. On the server I want to use the same project and just switch out the connection string to use the actual SqlServer database. Here is my connection string <add name="Entities" connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|re...

How to update a record from database via ADO.NET Entity Framework?

Hi, My WPF desktop-based application uses ADO.Net Entity Framework in order to connect with SQL Server database. In one of the windows I have a DataGrid with all data from tbl_users, when user selects one of the row (record) and clicks on Edit, application opens a new window with form, that includes all data that user can edit/update. ...

Dynamic Fetch an Inheritance in Entity Framework 4 POCO

Hey guys, Is there anyway to make a dynamic fetch in entity framework 4 If you have some inheritcance where a and b inherit from c Can you call one linq query to get a list of a, and b using the data set for c? ...

An Ajax accordion pattern in MVC

Hi, I am wandering what pattern to use for an area in my website that has several sub headings, which corresponding models. Say this is several parts of user data, which I have in several tables - like the ASP membership user table, a table with additional user information, and a table which may have several items to show for each user...

How to do filtering for many entities of many DataServices in one common class?

Hi I have an N-Tier database and every single table has a DataSetId and I absolutely want to be sure that the data is always partitioned correctly. Currently I'm using the QueryInterceptor attribute but it's messy and overly repetitive and prone to errors. Some new Dev could add a new table and forget to filter by DataSetId, or just ren...

Entity Framework Best Practices In Business Logic?

I am using the Entity framework for the first time, and would like to know if I am using in the best practice. I have created a sperate class in my business logic which will handle the entity context. the problem I have, is in all the videos I have seen they usually wrap the context in a using statement to make sure its closed, but ob...

Can I use Entity Framework for this?

Hi, I am working on a application which I want to expose to external world using ODATA. Let me first give you idea of that application. In that application I need to create a library that will allow the users to perform CRUD operations on the database. For this client has provided XSD , from which we need to generate the classes. Using...

What generates the SQL in Entity Framework?

I have tried to find this answer but cannot. What is generating the underlying SQL when using EF? Is it EF or the provider you are using? Also, is there any way to provide hints in order to change the way the SQL is generated? Thanks in advance ...

WPF Hierarchial Treeview Multbinding Mixed List Problem

I'm having a tough time solving this simple issue : I am using a treeview with HierarichalDataTemplate to show an hierarchy of two entities : Organization and Unit. The Organization has a many to many relation with itself as it could have sub organizations. And each Organization has one to many relation with Unit, as an organization co...

Entity Framework 4.0 - Versioning

Is this possible to implement with EF4.0? I have used NHibernate in the past and you can flag a timestamp column as a 'Version' column and it will enforce concurrency. Does this feature exist for EF4.0? If it does, are there any resources on how to set this up? If it does not exist, what alternatives do I have to handle 2 users editing ...

Using same entity class for two identical tables?

I have a web server control that is dynamically generated based on a table in my entity framework. Now a decision is being made to have an identically structured table with a different set of data, and I need some way to dynamically repoint my control to the other table. (I have made my case for keeping one table and just adding a flag...

How to run SQL Queries on EF ?

I am working on EF with C# and WPF as front end. I need to provide a UI for so user can create his own query and get the result. The UI will be list of tables and list of columns to select from (Not happy with UI. Need to improve but new ticks in my mind). So my question is how create, merge(existing query) and execute the queries. The...