entity-framework

Entity Framework EntityCollection in a WPF DataGrid

B"H I was wondering if there is any simple way to represent an EntityCollection (from a navigation property) in a WPF DataGrid. Specifically the issue is with deleting items. Displaying, Updating and even Adding items works fine. However the EntityCollection's Remove function only deletes the relationship, not the object. So when the ...

Entity Framework Model - Not allowing me to add certain tables

Whilst going through the "ADO.Net Entity Data Model" wizard, I select 3 tables from within a Database to add to my edmx file, and when the file is generated only one of the three tables is there. There was no error or warning to explain why the other tables haven't been added. If I try and add one of the failing tables on its own, again,...

Using inheritance in Entity Framework?

Hello, i have two tables in DB: Foo and Bar Using Entity Framework i want to create base entity which will contain properties which both tables have. For example Foo has columns Id,CreateDate,FooValue and Bar has Id,CreateDate,BarValue So BaseEntity should have Id and CreateDate properties Foo should inherit BaseEntity and have Foo...

How does the Entity Framework handle SQL Server Schemas?

We are developing an application against a SQL Server 2005 database that uses several schemas for security purposes. The application will be using EF 2 in the .NET 4.0 framework. What I'm wondering is how those SQL Schemas (Support, Admin, Employee) etc. can/will/should be represented on the EF side. Should I separate the various entit...

Creating Interface for ObjectContext

I'm trying to create an abstracted layer for ObjectContext. I understand OC is a Unit of Work, but I'm just not entirely how to write a good interface for it. Ideally I'd like to be able to swap out my 'RealDataContext' that implements IDataContext for something like a 'FakeDataContext' that would be fully in-memory. The reason for thi...

Entity Framework - Initial Save is slow

We are implementing a system using EF4 and WPF. We are noticing an issue with the initial saving of data: when the initial SaveChanges is run there is a 4 to 6 second delay when context.SaveChanges() command is run. Every subsequent SaveChanges is very fast with no noticable delay. This is not a major issue - but an annoyance none-the-l...

What is the best implementation for changing the database schema at runtime using Entity Framework 4?

We are building an ASP.Net MVC 2 multi-tenant application on SQL Server using the "single database, separate schema" model discussed, among other places, here and here, where each tenant has one or more users and is split out with its own, tenant specific, SQL Server schema. The application is using Entity Framework 4. In order for u...

How to use Entity Framework against multiple databases?

I would like to use EF 4.0 against Oracle. The challenge I have is that I have multiple databases (all with nearly identical schemas) for different clients. Is it possible to generate my CRUD layer once, and then point at the correct database at runtime based on user identity (or whatever criteria I need to supply)? I think I can hand...

Entity Framework SELECT 1 AS C1

OK, probably a really stupid question, but why is the query being generated by Entity Framework include "SELECT 1 AS C1" at the beginning? What is this for? For example, I have the following being generated: SELECT 1 AS C1, "Extent1".MY_ID AS MY_ID FROM MYTABLE "Extent1" WHERE 'test1' = "Extent1".MY_ID If I had written this manually...

Getting DB Server DateTime in application

I am using Entity framework and have 1 field in database AddedDate that is DateTime and not null, so I need to pass DateTime value. But the problem is I have to pass DB Server datetime. How can I manage in this sceario or how can I get DB Server datatime to pass this. I need to some unique solution, because I am this on many forms. E...

SQL Server "Delete on table may cause cycles or multiple cascade paths"

We have ASP.NET MVC2 project with EntityFramework mappings. How to delete row from Structure table with cascade deleting rows from Customer table (Customer table has "Zero or One - Many" association with itself and cascade deleteing of children Customers)? ...

Entities field lenght constraint

Hi everyone, I'm currently working with Entities (using visual studio 2008, FW 3.5 SP1). I created my entities from the database, and everything is ok, except that my lenght constraints on the string fields are not enforced. Browsing the internet, I found out that this is quite normal (see this blog post), and that Entities sends the da...

Executing Custom query -- Entity Framework

I want to execute custom query to get datetime of DB server select Getdate() using entity framework. How can I do this? Thanks ...

Error in generic repository method for Entity Framework

I'm trying to create a generic method to use in my base class for my repositories and I'm having an issue. Here's the method... public virtual T First(System.Linq.Expressions.Expression<Func<T, bool>> where, List<string> properties) { IQueryable<T> query = null; if (where != null) { query ...

Entity-Framework EntityConnection MetaData Problem

We are trying to build an EntityConnection dynamically so that different users are connecting to differnet databases determined at run-time. In order to do this we are testing the code found here: http://msdn.microsoft.com/en-us/library/bb738533.aspx. We have implemented this below: ' Specify the provider name, server and database. Di...

Where to specify business rules when using Entity Framework

I'm at a bit of a loss here. I have a one-to-many relationship between Project and Task and another between Task and TaskEvent. A Task only exists in the context of a Project and once assigned to a Project can't be changed to belong to another Project. A business rule states that a Task can only be deleted, and therefore removed from ...

Sysutcdatetime in Sql Server 2008 R2, is it deprecated ?

Hi, I developed an Asp.net application that uses Entity framework to connect to a Sql Server 2008(not R2) database. The client run the db script against a Sql server 2008 R2 database and it executed successfully. When the application is executed an exception is thrown: 'Sysutcdatetime' is not recognized as a built in function. After chec...

Exception while trying to deserialize JSON into EntityFramework using JavaScriptSerializer

I'm trying to deserialize JSON which I'm getting from an external source into an Entity Framework entity class using the following code: var serializer = new JavaScriptSerializer(); IList<Feature> obj = serializer.Deserialize<IList<Feature>>(json); The following exception is thrown: Object of type 'System.Collections.Generic.List1...

C# - Entity Framework add new object to ObjectContext

Hi, im working with Entity Framework, SQL and C#. i have a Table called Client and other called clients_phone. I have a form with a Xtragrid and using BindingSource I bind the IQueryable to the grid. myBindingSource = new BindingSource(); myBindingSource.DataSource = clients; //Clients it is the IQueryable<Client> myBindingSource.Dat...

Can I use EF with POCO adapter without database operations?

I understand that EF is tightly mapped against database. I also understand that we can generate POCO classes replacing EF based classes. I have the following scenario. We have a large framework of legacy non-serializable API written in .NET framework 2.0 (and we cannot modify that). We will not have direct access to database and all ...