entity-framework

Weird Constraint Exception with entity framework

I'm new to the Entities framework. One week earlier I've hit the common problem of the currentcontext that throws exception if used in a non-unique manner, but that was fixed. Today I have a new problem, a really new one because I do not even know why this is happening since I do think that I have the same code. Here is the error that ...

ASP.NET MVC: Set parent foreign key while creating a child entity

Hi, I have: "Task" Entity that holds a foreignkey to a "Project" Entity. In the MVC model I have a ProjectDetails view where i have a ActionLink for creating a new Task I need to set the ProjectReference for the new Task object. The projectReference is passed by a url parameter (CreateTask?projectId=4) In the projectDetails view I ha...

How can I add constraints to an ADO.NET Entity?

I know how to mark a group of fields as primary key in ADO.NET entities but i haven't found a way to declare unique constraints or check constraints. Is this feature missing on the designer or on the framework? Thanx. ...

create entities for a dynamically created database in SQL Server

I have an application where I create database's dynamically in a SQL Server using Server Management Objects through my application. I want to use the Entity Framework to access this database when it has been created, is this possible? As I can not generate Entity classes from a database in VS. I do have the structure of the database ...

Entity binding to select table columns

I am just learning to use the Entity framework and I wondered how I can bind to a select few columns with my WPF Toolkit datagrid? Can someone give me an example? I've tried to set the DataContext to the Person Entity for example and then set the Itemsource binding path to a single column of the table, but it does not work. ...

Entity Framework using a join when querying a table with 1-1 identyfying relationship

Let's say I have a Users table and a UserDetails table related with identifying relationship ( UserId is a PK of Users and PFK of UserDetails). What I've noticed is that when I'm querying Users entity, EF generates SQL with a clause: Users left outer join UserDetails which doesn't really make sense, since only Users columns are selec...

Spatial data/Geography in SQL Server 2008, OR mappers and C#

I'm developing an application in C# that will use and store geographic locations using the data type "Geography" in SQL Server 2008. I was planning to use the Entity Framework but soon discovered it lacks support for spatial data. Does anyone have experience with or know of other OR mappers with spatial support? The system will have few...

.NET RIA Services - work with custom data layer

There is a web-application that works with Business Logic Layer (BLL). The BLL gets data from the Data Access Layer (DAL). The DAL gets data from DB through and does custom mapping. At the moment it is required to add into the web application some functionality that will be Silverlight-based. It is planned to use .NET RIA Services for t...

Column Sequence and the Entity Framework

So, when you bind a collection of Entity objects to a grid component, the grid displays those fields in the sequential order they are found in the SQL Table they came from. This shows that the ordinal position of the fields are associated with their corresponding entity properties... somehow or other. So here is the question: How can ...

SQL View not working with Entity Framework MVC 1.0

I have a SQL View (SQL Server 2008) that contains 4 columns and works just fine in SSMS. I added the SQL View via Database Update to my Entity Framework model. No complaints, but I noticed that EF decided to make 2 of the 4 columns EntityKeys. The problem I'm having is that when I run the query in my app code, I get the right number...

Entity Framework 4.0 Unit Testing

Hi, I've implemented unit testing along the lines of this article with a fake object context and IObjectSet with POCO in EF4. http://blogs.msdn.com/adonet/archive/2009/12/17/test-driven-development-walkthrough-with-the-entity-framework-4-0.aspx But I'm unsure how to implement a couple of methods on my fake object context for testing. ...

SQL injection concerns

ok i use this route routes.MapRoute( "Catalog/Data", "Catalog/{*data}", new { controller = "Catalog", action = "Category", data = "" } ); the Url looks something like http://localhost/Catalog/Computer/Harddrives/internal Data beening the Computer/Harddrives/internal part i split it apa...

Using objectContext after an exception was thrown

See this scenario: 1-I have a single ObjectContext instance shared between multiple business logic layer classes to avoid identity and tracking problems when using multiple object contexts. 2-An object of a class tries to create and insert an entity but an exception takes places (because of a foreign key constraint, unique key constrai...

Model Binding With Entity Framework (ASP.NET MVC)

Earlier I created an AddClient page that (when posted) passed a client object and I used db.AddToClient(obj) in my repository to persist it. Easy stuff. Now, I have a details page whose save submits a post to an action "UpdateClient". Before that action is hit, my custom model binder creates my Client object and it's conveniently hand...

Linq - OrberBy the minimum value of two colums

I have an entity set that contains two DateTime properties. I want to order the set by the minimum value of the two properties. How can I do this with a lambda expression. ...

Linq to entities insert EF 1

I have a 2 Entity : Person (Id, CategoryId) and Category(Id). Now when I try to insert a new Person with only the Id and CategoryId it throws an exception about the Person having a relationship with Category. The following code doesn't work: Person newPerson = new Person(); newPerson.Id = 1; newPerson.CategoryId = 1; context.AddToPer...

.net entity query

Hello, I'm have an issue with this entity query that I am hoping to get some help with. Overall what I am trying to do is query for entries in the GoalNotes table as well as include the Employee reference for each note. The GoalNotes table has a foreign key relating it to the Employee table. I am then trying to query the GoalNotes tab...

Can the where-condition in this LINQ-query be optimized?

Hey! I have this LINQ-query: bool? a, b, c; from i in _ctx.SomeEntitySet where (a == null ? true : i.IsA == a) && (b == null ? true : i.IsB == b) && (c == null ? true : i.IsC == c) select i; I only want to take the condition IsX == x in...

Lambda expression for Entity Framework query

I'm stuck trying to map this sql: select dt.Id, dateadd(dd,datediff(dd,0,dt.CreatedAt),0) as Ct, DId, Amount from dt, ad where dt.ADId = ad.ADId and ad.Id = '13B29A01-8BF0-4EC9-80CA-089BA341E93D' order by dateadd(dd,datediff(dd,0,dt.CreatedAt),0) desc, DId asc Into an Entity Framework-compatible lambda query expression. I'd appreciate...

Use EntityFramework to save Items (with new elements in multiple tables) after being sent over WCF to a silverlight app

I have a web app that sends ADO Entity data model classes over a WCF service to Silverlight. Imagine this simplified structure for the database [Item] Id Name [ItemDetail] Id ItemId value While the Item is in my SilverlightApp I add an ItemDetail to the Item, this is ADO so it's something like: var fv = new ItemDetail(); ...