entity-framework

Entity Framework Overwriting ID Values

I am running into the same exact problem as asked in this question: Entity Framework, Foreign Keys, and EntityKeys where my Foreign ID key values are being reverted back to 0 before I am able to send the information to the database. This results in the error: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Sel...

How do I clear object context

If I ran several queries and ObjectContext was populated with entities how do I clear the context if I don't need those entities anymore. I know that I need to dispose the context as soon as possible, but in this case it is not possible. So is there any way that I can remove those objects from the context? ...

ASP.NET MVC using the Repository Pattern

Currently im using EF and using its datacontext directly in all of my actions, but since i started reading about loose coupling and testability im thinking that thats not the best way to go. Im trying to understand all the pro's and con's before i start refactor all my current code. Problem 1: Considering that every entity needs its own...

Entity framework 4 updating the model when a table changes

Hi, I am using Entity Framework 4. I have my model file with my tables on it. If I go and add a new column to one of my tables (in SQL Server) how do I update the table in the model without having to go and delete and re-adding it to the model? Thanks ...

Association between two tables where keys are different data types.

Tables Departments Employees I'm trying to associate: Departments - dept_code : char(4) Employees - dept : varchar(4) But I receive the following error, Error 2039: The conceptual side property 'DEPT_CODE' has already been mapped to a storage property with type 'char'. If the conceptual side property is map...

Entity Framework - how to join tables without LINQ and with only string?

Hi all, I have a question about Entity Framework. Please answer if you know answer on this. I have such query : String queryRaw = "SELECT " + "p.ProductName AS ProductName " + "FROM ProductEntities.Products AS p " + "INNER JOIN CategoryEntities.Categories AS c " + "ON p.CategoryID = c.CategoryID "; ObjectQuery<Db...

Entity Framework Error Updating Master Details Items

Hi everybody im trying to add new items to master detail records and i get the error: The INSERT statement conflicted with the FOREIGN KEY constraint "invOrden_InvOrdenDet_FK1". The conflict occurred in database "InventarioSIAIplus", table "dbo.InvOrden", column 'IDorden'. The statement has been terminated. This error Happens when i ad...

Problems binding Self-Tracking Entity's Navigation Property WPF

I have a WPF application consuming data using Entity Framework 4 and Self-Tracking Entities. In which I have a window with 2 controls in it, one that shows the "Details" portion of an object using a ContentControl and templates from a merged resource dictionary. Another with a ListBox of Groups the object in question belongs to and a Com...

Error message with Entity Framework and Function Import

I have a DB stored procedure that returns a float. The Stored proc does calculations of inputs and spits out a "Rating" based in the inputs. I was able to update the Model and perform a function import, but when I try and use the new function in Linq i get the following error. Function metadata used in DbFunctionExpression must a...

Entity Framework 4: Inheritance (table per type) - Derived table has a composite PK

Hi there, Is it possible to have "table per type" inheritance in the Entity Framework 4 if the derived table has a composite primary key? Here is my table setup: TABLE: ConfigurationKey (Base Entity) PK: Id TABLE: ConfigurationKey_Device (Derived Entity) PK: ConfigurationKeyId (FK to ConfigurationKey.Id) PK: DeviceId (FK to Device.Id...

MARS in SQL Server 2000

Hello Friends, I am working in ASP.Net MVC 1.0 and SQL Server 2000 using Entity Framework. My faulty controller code is given below: int checkUser = id ?? 0; string userNameFromNew, userNameToNew; if (checkUser == 1) { userNameFromNew = "U" + Request.Form["usernameFrom"];...

FunctionImport in entity framework 4 issue

Hi, I'm using entity framework 4. I have a stored procedure that just updates one value in my table, namely the application state ID. So I created a stored procedure that looks like this: ALTER PROCEDURE [dbo].[UpdateApplicationState] ( @ApplicationID INT, @ApplicationStateID INT ) AS BEGIN UPDATE [Application] S...

Creating a many to many editor for ASP.Net using Entity Framework 1.0

I'm moving a bunch of code to Entity Framework and I need to represent a many to many link visually. This is done by a list of checkboxes with some of them checked to represent the join table. I've looked at Dynamic Data and while that works well, I can't see how to extract their ManyToMany_Edit.ascx file and use it in ASP.Net. Another ...

Entity Framework POCO - Refresh a natvigation property

I am having some trouble with refreshing the related collection of entities. Essentially the problem is as follows: public class Student { public virtual ICollection<Lecture> Lectures { get; set; } public void AddLecture(Lecture lecture) { Lectures.Add(lecture); } public void CancelChanges() { ...

Checking for a null object in EF causes an additional database hit ... how come?

I am working with Entity Framework ... I have a database table for Patient which has a non-enforced foreign key relationship to the Employee table so I can associate a manager to a patient. I created my entity in EF for the Patient, the Employee and an association between Patient and Employee, which I name to ManagerEmployee. I also...

How to use Include with Lambda in EF?

According to this article you are suppose to be able to do includes using a lambda expression http://romiller.com/2010/07/14/ef-ctp4-tips-tricks-include-with-lambda/. For example ... var blogsWithPosts = context.Blogs.Include(b => b.Posts); So where I have ... IQueryable<Data.Patient> query = ctx.ObjectContext.Patients ...

Does it make sense to use F# for BLL implementation?

Do you think it could be a good idea to use F# for implementation Business Logic Layer? I am going to use Entity Framework as 'data mapper' and implement UI logic using C#. Any thought are welcome. I would appreciate any help! Thanks. P.S. What is a purpose of that? I am newbie in F# and would like to experiment with that Language (te...

Implementing Navigation Properties in Entity Framework

Hey folks, I've been learning MVC 2 and I have pretty much everything understood except for the model part of things, I understand what the model is but actually implementing it has me confused. Here's my situation, I have my DB which has 3 tables; Ideas - table of ideas Tags - table of tags IdeaTag - link table connecting the above 2 ...

ADO.NET Data Services with EF implementing table per concrete type (TPCT) inheritance

I am working with a SQL data source that has duplicate data in multiple tables. I have no control over the database. For my project, I've created an EF model and an ADO.NET data service (using VS 2008) that exposes it. I also have a .NET client application that consumes the service. Now, these db tables have a large number of fields co...

Creating custom objects for wcf

Hi, I have an existing web application that uses EF and POCO objects. I want to improve the client experience by exposing some of my objects through WCF(JSON). I have this working fine but where I am unsure is how to handle derived objects(not sure if that is the correct term) or IEnumerable anonymous objects if you will. Let's say I ...