entity-framework

linq: grandparent - parent - children query

Hi, I have an entity model and I've been looking to write a linq query that returns counts of children and parents for each grandparent. I need to output 3 columns: Name of Grandparent | Count of Children | Count of Grandchildren protected void Page_Load(object sender, EventArgs e) { using (FamilyModel.TheConn myEntities = new Fa...

Programming against interfaces & Entity Framework 4.0

I'm trying to figure out if it would be possible to stick to the mantra "Program against an interface, not an implementation." while using the Entity Framework 4.0. While I found a page explaining how to stick to aforementioned rule while using Linq-to-SQL (look here) I'm very keen to know if it would be possible to do that with the Ent...

Entity Framework Insert Child Entities

Hi all, I am trying to persist the collection of child elements, the solution works but I would like to ask the more experienced people if the approach is the right one? public bool InsertNewActionHistory(ActionHistory actionHistory) { bool result = false; using (TransactionScope transactionScope = new TransactionS...

Primary Key issues when Migrating "Legacy" SQLite Databases to use the Entity Framework

I have recently started work on a project that has already been running for several years. The application is written in c# using Windows Forms for the UI and SQLite for the database. The database is currently accessed using ADO.NET via the System.Data.SQLite namespace. From time-to-time clients have received application and database up...

Linq To SQL migration to Entity framework 4

We are planning to migrate to .net 3.5 and evaluating Linq To SQL and Entity framework. Considering what people are saying every where on internet that EF 1.0 is buggy, complex, has suboptimal designer support etc, if we pick Linq to SQL - do you think we will be able to migrate it to EF 4 when the time comes? The question arises becaus...

Entity Framework and WCF Data Services : Calling business logic after persisting entity

We have an Entity Data Model which is used by a WCF Data Service that needs to run some business logic after persisting an entity to the database. In this case it needs to pass the id generated for the persisted entity to another service via a WCF web service call. The question is how do we run some business logic after saving the enti...

Linq2Entities Include with Take - load issue

Note: I know there are a number of questions around for issues with Linq's .Include(table) not loading data, I believe I have exhausted the options people have listed, and still had problems. I have a large Linq2Entities query on an application I'm maintaining. The query is built up as such: IQueryable<Results> query = context.MyTable ...

How to Clone POCO entity and add to context

I am using EF4 and I have create POCO objects with proxies from my database structure . I have a POCO (object) which has lots of relationships to other entities. I created a deep copy of the object using DataContractSerializer and BinaryFormatter and lets call it clonedObject. function used for cloning is: public T CloneProxy<T>(T sou...

ASP.NET 4 SQL Methods?

Hi, Currently working on an ASP.NET web app and am starting to realise i'm writing the same Boiler Plate Code Over and Over Again.. i.e. SqlDataReader myReader = null; SqlCommand SQLcmd = new SqlCommand(); SqlConnection SQLConn = new SqlConnection(); String SQLStatement = "Select this 'nd That"; ...

how can I add table prefixes to tables created using model first in EF4?

My client has a db table naming convention that requires me to prefix all tables with an application specific prefix - like "myapp_" - I am using EF4 with the model first approach. I can specify a custom db namespace but they do not want to introduce a new namespace for this app - none of their other apps use namespaces other than dbo....

What is the difference between these two LINQ queries?

Looking at the profiler I see a few differences. The second query which uses the include will in fact return data from related to the secondary table CountryCodes. This part makes sense to me. I don't however understand why this query has two joins. First it does a regular inner join between CountryCodes ands CountyCodeTypes (on the ...

What does your company use for database access and mapping? Does this make you happy or sad?

I started out at a medium sized financial firm, and everything was done using a home brewed ORM. I've recently moved to a web shop and it's a mix of ADO.NET and linq to sql. I'm wondering what other people are using at their shops, and why? Are you happy about this, or do you wish you were using another approach? Do-it yourself usin...

Entity Framework 4.0 model from a database in MySQL server.

Hi all, I would want your opinion about building the Entity Framework 4.0 from a database which is on a (remote) MySQL server. Is there anyone who has experienced this "combination". Perhaps some MYSQL server configuration... anything. Thanks! ...

Entity Framework and SqlDateTime overflow best practices

System.DateTime can take a wider range of values than SQL Server's DateTime. Hence there is class System.Data.SqlTypes.SqlDateTime which mimics the later. Consequently I would have expected Entity Framework to choose SqlDateTime, but it didn't. So my questions are... What are the best practices to insure that your DateTime values wi...

Return Type for Collection from LINQ Query

I have a method, that returns a group of accounts Public Shared Function GetAllNotesByUser(ByVal UserID As Guid) As Account (??) Using db As New MyEntity Dim query= (From A In db.Account _ Where A.aspnet_Users.UserId = UserID _ Select A) Return query End Using End Function ...

MySQL with Entity Framework - what am I doing wrong?

...

Entities Framework 4 Code First: Business Methods

Could anyone tell me where is the best place to put my business methods when using EF4 code first POCOs? Should they go in the POCO class? E.g. public class customer public property Id as int32 public property Name as string public property Archived as boolean public sub MarkAsArchived me.Archived = true end...

Creating XML and XSD files based on .NET entities

Hi I've been looking around for this for quite some time and cannot seem to get anywhere. I need to find a way to accomplisht the following two tasks, based on a .Net Entity object: Create an XML file that contains the data in this entities, complete, with cascading nodes (representing foreign key relationships, basically). I've consi...

EF4 - Foreach local variable with static data

Hi guys.. I'm using EF4. I've found a very annoying issue. I have a db view that I've dragged into my Entity Model class. When I try to iterate over the hole collection, the data displayed, it's almost the same that the first objects... I've tried enabling Lazy Loading, but nothing works.. it's a really simple snippet.. why doesn't work...

Sorting Gridview with Entity Framework.

I have a method private void BindGrid() { dataContext = new VTCEntities(); string SortExpression = "DisplayName"; string SortDirection = "ASC"; int skip = 0; if (this.ViewState["SortExp"] != null) { SortExpression = this.ViewState["SortExp"]...