Entity Framework

Entity Framework
EF Inserts Failing Because of Missing Association in SSDL

I just found that Entity Framework (4.0) can stumble on One-To-One relationships if the EDMX's schema storage layer (SSDL) is missing the association that represents the Foreign Key in the database. I suppose this makes sense, but it's only obvious to me in hindsight. I don't know how my EDMX ended up missing the SSDL association for the Foreign Key, but it was missing. However the the Conceptual Layer had the relationship, so the diagram made it look like it was associated. And because this is a supported scenario, it didn't complain at me that I was missing anything....

posted @ Thursday, January 19, 2012 4:37 PM | Feedback (0)

Don't Reuse Context with Entity Framework Self Tracking Entities

With EF Self Tracking Entities, it appears that using a single context for a "read" and then a subsequent "save" does not work. I guess I could let this one go as "By Design", but that doesn't mean I have to like it… The Scenario: EF Self Tracking Entities for an MVC 3 site I have an MVC3 site wherein I'm using Self Tracking Entities. These are exposed by repositories that I'm injecting into the controllers via Ninject. Since we're letting our IoC container create these items, the lifetime of the instances are "per request". Inside the...

posted @ Tuesday, November 01, 2011 1:27 PM | Feedback (1)

WPF & Entity Framework 4 - Tales from the Trenches

I recently presented "WPF & RF4 - Tales from the Trenches" at the Cleveland .NET SIG. This presentation reviews tips, tricks, and lessons learned from building real world apps with Windows Presentation Foundation 4.0 and Entity Framework 4.0. Whether you’re doing desktop, Silverlight, or web development, the EF T4 template tweaks, MVVM usage, Undo/Redo implementation, and Reactive programming tips reviewed in this presentation should come in handy. The Photo Tagger sample application includes implementations of these topics and issues. I'd highly recommend pulling this down and taking a look. Downloads WPF...

posted @ Wednesday, October 13, 2010 7:00 AM | Feedback (6)

.NET SIG: "Bag O' Tricks - WPF and Entity Framework" (Oct 12th)

Just wanted to plug my upcoming presentation at the Cleveland .NET SIG…. Oct 12th at the Microsoft offices in Independence, OH. Topic will be "Bag O' Tricks: WPF and Entity Framework" I plan to share lessons, tips, and tricks from my experiences with WPF 4.0 and Entity Framework 4.0. Even if you aren't using WPF, I think you may find these topics useful since many are are also applicable for other technology stacks, including Silverlight, Windows Phone, Windows Forms, and even web apps. EF Self Tracking Entities ...

posted @ Friday, October 01, 2010 10:41 AM | Feedback (0)

I <3 LinqKit – Dynamically build arbitrarily complex Linq Queries

In some cases, I need to be able to build a query that has a variable set of OR conditions. This is not simple with the default language constructs and extension methods. It’s simple to dynamically build an expression that includes AND parameters, because that is what the WHERE() extension method does. Not so easy for OR’ing together a bunch of conditions. Enter LinqKit. This is a great library. It provides some easy to use (but powerful) extension methods that let you “Or()” some conditions together. A common case is where you get a list of values that you need to add into...

posted @ Wednesday, April 14, 2010 11:42 AM | Feedback (0)

Entity Framework 4.0 doesn’t enforce MaxLength metadata

I’m a little flabbergasted that Entity Framework does not do anything to enforce the MaxLength on string values. It just passes this responsibility down to the database and catches the resulting (unhelpful) exceptions. I suppose that there is a justification for this, but from an notably simplistic perspective… Why should I start a transaction and waste precious DB resources, only to get some generic “String or binary data may be truncated” error message back. It would be trivial for EF to use the metadata to ensure that you cannot push a 10 character string into a field that...

posted @ Tuesday, April 13, 2010 3:42 PM | Feedback (3)