LINQ to XML with Hierarchical XML, Optional Elements, and Namespaces
Recently I had an interesting task to consume a particular XML document and populate a C# object from it. The structure of the XML document looked roughly like this: 1: <root xmlns=" 2: <entry> 3: <id>1</id> 4: <title>abc</title> 5: <content> 6: <div xmlns=" 7: <table> 8: <tr> 9: <td>Item1</td> 10: <td>111</td> 11: </tr> 12: <tr> 13: <td>Item2</td> ......
Posted On Tuesday, December 29, 2009 11:34 PM | Comments (2)
Comparing Entity Framework 4 New Stored Procedure Support to LINQ to SQL
The next version of Entity Framework has many new features, many of which are enabling it to catch up with features previously available in other frameworks like LINQ to SQL. One of these new features is the updated stored procedure support. In previous versions of EF, working with stored procedures was quite limited and really only usable with CRUD operations that were mapped to already defined entities. With EF 4, you can start with your stored procedure and have the designer automatically generate ......
Posted On Wednesday, December 16, 2009 11:24 PM | Comments (8)
RockNUG Code Samples
Thanks to everyone who attended my LINQ to SQL presentation at RockNUG last night. The code samples can be downloaded here: LINQ to SQL demo code. As a point of clarification from last night’s Q&A session after the presentation regarding using LINQ to SQL with true POCO classes that do not even have [Column] mapping attributes, you can have a class like this: 1: public class Contact 2: { 3: public int ID; 4: public string FirstName { get; set; } 5: public string LastName { get; set; } 6: public ......
Posted On Thursday, November 12, 2009 1:11 PM | Comments (0)
Linq - Handle Insert/Update/Delete of child entity in tiered application
Recently I've done a series of posts all related to using Linq in a tiered application: Linq Table Attach() Linq Table Attach() based on timestamp or row version Handling Attach() with child entity objects Exploring DataContext in more depth The various posts (which have been influenced by this MSDN article) have focused on a DataContext that looks like the diagram below. The Contact class generated has a child collection property of Addresses which is of type EntitySet<Address>. This distinction ......
Posted On Sunday, December 30, 2007 11:10 PM | Comments (34)
Be mindful of your DataContext's "context"
In a previous post here, I discussed implementation of Attaching Linq entities to a DataContext. In that post, I showed an implementation of utilizing a Detach() method that I originally based on this post here. The implementation boils down to the need to reset EntityRef<> references back to their default - otherwise, it will try to attach the parent objects (which is often not the goal of your code as this is often just reference data). Consider the DataContext below: The fundamental problem ......
Posted On Thursday, December 27, 2007 8:48 PM | Comments (8)
Linq - Attach an entity that is not new, perhaps having been loaded from another DataContext.
This exception using the Linq Attach() method is somewhat perplexing at first: System.NotSupportedException: An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported. This blog post here *sort of* pointed me in the right direction. But I found the *WHY* confusing and I found the example confusing. The following is my implementation of the suggested solution from the previous post. First, consider the following ......
Posted On Tuesday, December 25, 2007 2:20 PM | Comments (26)
LINQ to SQL Again??
Tomorrow night I’ll be at RockNUG presenting LINQ to SQL. Yes, LINQ to SQL. Again. In the last 2 years I have presented LINQ to SQL numerous times at various user groups and code camps. Why do I keep getting asked to present LINQ to SQL? Isn’t LINQ to SQL dead? Answer: No. LINQ to SQL is not dead! This confusion all started back in October 2008 with a seemingly innocuous post on the ADO.NET team blog discussing the emphasis that Microsoft was going to put into the Entity Framework going forward. ......
Posted On Tuesday, November 10, 2009 9:26 PM | Comments (4)
CMAP Code Camp Fall 2008 - Code Samples
The code samples from my recent presentation at the Maryland CMAP code camp can be downloaded here:

N-Tiered LINQ to SQL

MVC and Unit Testing
Posted On Monday, October 27, 2008 11:20 AM | Comments (1)
LINQ to SQL - Return Scalar Value from a Stored Procedure
One of the best things about LINQ to SQL is that is really does have solid support for stored procedures. However, it's not quite as friendly as dynamic LINQ to SQL with scalar values because you can't take advantage of anonymous types. Instead you must return an actual known type. Furthermore, this can't be a primitive so you can't return string or bool directly. You also can't use a class that doesn't have a default (parameterless) constructor so that also rules out nullable types like Nullable<bool>. ......
Posted On Tuesday, July 8, 2008 10:55 PM | Comments (18)
MVC Control Extensions - Automatically Set Control Names
To set a normal text box in the MVC framework, the most typical code would look like this: 1: <%=Html.TextBox("FirstNa... ViewData.Model.Contact.Firs... The key here is that you should set the name of the textbox to be the exact same name of the property name. If you do this, then it enables you to use extension methods such as the UpdateFrom() method to automatically populate your object from Request.Form parameters when you post to your controller action. This is all well and good but ......
Posted On Sunday, June 22, 2008 11:03 PM | Comments (4)
Full LINQ Archive

View Steve Michelotti's profile on LinkedIn

profile for Steve Michelotti at Stack Overflow, Q&A for professional and enthusiast programmers

Google My Blog

Tag Cloud