Entity Framework
There are 8 entries for the tag Entity Framework
Wednesday, January 25, 2012 2:02 PM | Comments

If you drink from the fire hose read Ayende’s blog you would notice a lot of Anti-Repository talk over the past couple years – which I fully agree with. Back in 2009 he declared repository is the new singleton, stating: My current approach for data access now is: When using a database, use NHibernate’s ISession directly Encapsulate complex queries into query objects that construct an ICriteria query that I can get and manipulate further When using something other than a database, create a DAO for that, respecting the underlying storage implementation Don’t try to protect developers Naturally he gets a slew of comments asking how he handles certain scenarios without using the repository...

Thursday, July 22, 2010 10:35 PM | Comments

A common requirement for many applications is filtering rows of data based on the current user. A simple example is an e-commerce site which would want to make sure a Customer who is logged in is only able to view his own Orders. Another example would be a payroll site that would want to make sure a user could only view their own Employees. These are of course trivial examples, and could be solved in a number of ways. My concern is that often times the responsibility of security is placed upon each individual developer to make sure they are calling the right methods on your repositories. This may seem fine to many readers, and we could debate whether or not this should be the case, but my current take on security is to let the application infrastructure handle those details for you. What if I could easily...

Thursday, April 22, 2010 11:28 AM | Comments

This post is part of a series on customizing the Entity Framework T4 templates I have been using EF4 for a little while now, and have been taking advantage of the code-generation extensibility afforded to us by T4 templates. This series of posts will describe the enhancements I have made to the default T4 template, and how you can take advantage of this functionality yourself. Part 1 – Generate an IDatabase interface to represent your Data Context Part 2 - Derive entities from a custom base class Part 3 – Suppress Code Analysis warnings from the generated code Protip before we get started Before working with T4, you will absolutely want to install a helpful tool to...

Tuesday, February 9, 2010 9:57 AM | Comments

As a brief recap, the reason this post even exists is because the generated code from the EF4 designer does not properly suppress code analysis warnings. In that post, I mentioned that I would provide a proper T4 template and tutorial on integrating it into your EDMX model. This post details the steps to creating and customizing an Entity Framework 4 T4 template. T4 (the Text Template Transformation Toolkit) is the code generation technology built into Visual Studio. Thankfully, the EF4 designer has been enhanced to support customizable templates so that developers are free to change the code that is generated for your ObjectContext and Entity classes. To get started, I am assuming you already have an EDMX file that has been generated from your database. Beta Note These steps were written for Visual Studio 2010 Beta 2, so they may change slightly before RTM....

Thursday, February 4, 2010 9:32 AM | Comments

Update I have published the instructions and provided a template that can be used to properly suppress code analysis.   Starting a new project opens the doors for some great things. One of those things for me, was adherence to code analysis from the get-go. Visual Studio 2010 in particular has great Code Analysis Rule Set support allowing teams to carefully dictate which rules they wish to apply and suppress. Unfortunately, it wasn’t long before the decision to use Entity Framework 4 put a nice little wrench in my code analysis plan. (As an aside, I will blog more about my decision to use EF4 at a later date -- but long story short, it had to do with the large legacy database that we would be working with). Shortly after loading the existing database into the EDMX and compiling, I was greeted by nearly 1300 code analysis warnings, ranging from naming of properties to...

Wednesday, January 27, 2010 4:45 PM | Comments

Unable to update the EntitySet 'PlanPriceHistory' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. While I was getting my feet wet in Entity Framework 4 (from the Visual Studio 2010 Beta 2 release), I generated my EDMX from an existing legacy database. All was going well – for a few days in fact, until I attempted to Insert an entity to a specific table (seen below). After some digging around in my model/EDMX configuration thinking something was wrong in there, I decided to open the actual table definition for the EntitySet (‘PlanPriceHistory’) that EF was complaining about. The problem with this particular table is that it logically uses a composite primary key (but was mistakenly not defined as such in the database). The fix was as simple as highlighting the columns and...

Tuesday, February 26, 2008 5:59 AM | Comments

This post is a follow-up to an article I wrote a few weeks ago, ADO.NET Entity Framework Comparison Frustration. As a quick re-cap, I was simply trying to filter a list of users with a LINQ query expression by comparing custom classes, not primitive types. TorvusEntities entities = new TorvusEntities(); // Pull my Account Entity from the database Account matt = entities.Accounts.First(a => a.AccountId == 10); // Attempt to get all Teams by a Team Owner var teams = from t in entities.Teams where t.Owner == matt select t; However, an exception was thrown. Unable to create a constant value of type 'Closure type'. Only primitive types (for instance Int32, String and Guid) are supported in this context. So I left it at that....

Friday, February 1, 2008 7:16 AM | Comments

Today I began playing with the ADO.NET Entity Framework. This framework looks very promising and I plan on experimenting with it heavily this weekend, so expect some more ADOe articles over the next few weeks. [Update: I discovered more about this subject while reading in-depth the MSDN articles on the ADO.NET Entity Framework. I have updated my conclusions at Entity Framework Comparison Frustration: Explained] Without going into too much detail, ADOe is very similar to LINQ to SQL. It is essentially a more advanced OR/M that is built into the .NET framework and integrated heavily with Visual Studio designer support, complete with a few snap-in panes for visually mapping your database schema to your CLR objects. I found this post on MSDN explaining the major differences between LINQ to SQL and the ADO.NET Entity Framework. Later I will go into much more detail about ADOe in general, but for now I wanted to...