Using the Entity Framework in a Layered Architecture

Thursday, July 03 2008 - , , , , - 1 comments

My July 2008 Data Points column was just released on the MSDN Magazine web site. This month I demonstrate how to use the Entity Framework in a multi-tiered architecture passing entities through the layers via WCF. The code sample is available from their web site too.

The Entity Framework has been a much discussed topic of late. Many articles discuss and show how to build different types of models and facets of the Entity Framework. This article shows one way to integrate the Entity Framework’s models into an application that uses layers and a form of the MVP pattern.

July2008

TextBox is Not Behaving in Silverlight 2 Beta 2!

Wednesday, June 18 2008 - , , - 3 comments

I’m putting together some samples for an article for my Data Points column in MSDN Magazine on writing a line of business application with Silverlight communicating with WCF, and I ran into a few issues I did not expect. The one that really confused me causes the TextBox controls in the Silverlight application to:

    • not show the cursor in the TextBox (although I can type)
    • not show the contents being selected in the TextBox
    • breaks the TwoWay binding mode

I was living with the first 2 because I thought, eh, what the heck, its beta and I obviously hit some weird occurrence. But when the binding only worked one way from the source to the target TextBox controls, I knew I had a real problem. The TextBox controls when bound with Mode=TwoWay were not updating the source when I typed in the TextBox controls (and lost focus of course).

After a few posts in the Silverlight forums and some emails with some fellows at Microsoft, it was confirmed that there is a bug in the Silverlight 2 Beta 2 that causes the TextBox to not behave properly. The confusing aspect is trying to reproduce the problem. So I created a simple Silverlight user control, shown below:

<UserControl x:Class="TextBoxTester.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBox x:Name="tbMsg" Text="Hello World" Height="30" Width="Auto"></TextBox>
    </Grid> 
</UserControl>

 

When this control is run from Visual Studio, there is no problem … nor is there a problem if I browse to the html page that hosts the compiled Silverlight application. WTF, says I! But if I browse to the html page that hosts the app, then REFRESH the page in the browser forcing the Silverlight control to reload the TextBox starts behaving badly. I tried this several times and it always reproduced it. However there are people I gave this same code to who saw the same behavior and others who did not. So there is obviously some other force intervening in this that I am not aware of still.

There are no error messages, no informational messages, nothing at all except a misbehaving TextBox control.

Anyway, I have been told that there is a bug regarding the TextBox control and that it will be fixed in a future release (prior to RTM of course). The causing factors are not completely known to me, but in case you run across this I figured I would shed a little light on it. The way I get around it for now is to click in the address bar of the browser, then click back on the Silverlight control. This seems to put the TextBox’s world back in order.

Entity Framework Q&A - Lazy Loading, ObjectContext, and LINQ

Monday, May 05 2008 - , , - 0 comments

I've received hundreds of questions regarding the Entity Framework and LINQ. Obviously developers are very interested in the Entity Framework and its data access and modeling implications. 

I responded to some of the most frequently asked questions in the May 2008 Data Points column. Topic includes:

  • Why use Entity SQL when I can use LINQ to get to entities?
  • What is the role of ObjectContext?
  • How do explicit and eager loading work LINQ and the Entity Framework?
  • How do I see the SQL that will execute?
  • What can I do with complex types?
  • How do I create a complex type?

You can find my Data Points column in the May 2008 MSDN Magazine issue online.

2008-05-MSDN

 kick it on DotNetKicks.com

Standard Query Operators with LINQ

Friday, April 04 2008 - , , , - 0 comments

In the March issue of MSDN Magazine's Data Points column I explore a variety of the Standard Query Operators and how they work with LINQ. Here is a summary of the article:

In this month's column I will perform practical queries and operations with LINQ, using both LINQ to Objects and LINQ to Entities. I'll query a single collection of entities and dive deeper into a hierarchical set of entities using their navigation properties. I'll also show how you can apply many of the standard query operators to arrays and collections. I will demonstrate how LINQ's standard query operators are enhanced using lambda expressions and how they can let you parse specific information from a sequence and perform complex logic over a sequence.

You can check it out here.

2008-03-MSDN

Designing an Entity Data Model

Sunday, January 20 2008 - , , , - 0 comments

Just published is my article on Designing an Entity Data Model with the Entity Framework tools. This article is part of my Data Points column in the February issue of MSDN Magazine. A few months ago I wrote an article discussing an overview of the Entity Framework and examining the CSDL, SSDL, and MSL that defines the EDM. When that article was published the tools were not available, so in this article I  decided to explain how the tools work which coincides nicely with the previous article's explanation of the XML files (CSDL, SSDL, MSL). The EDM designer sits  on top of the XML files and uses the XML information to represent the model. Likewise, the model can be changed using the designer tools which then updates the XML under the covers.

I will be having a few more articles in the upcoming months that explain more about the Entity Framework and its auxiliary parts. For next month's issue I plan on going through many of the Standard Query Operators that can be used with LINQ to objects/entities. Also, if you are planning on attending DevConnections in Orlando in the Spring (this April), I will be presenting 2 different 1:15 minute sessions on the Entity Framework there as well.

As always, if you want to review my history of articles, please visit my articles history page where you can find them all listed.

2008-02-MSDN

Articles

Friday, December 21 2007 - , , , - 0 comments

July2008

MSDN Magazine – July 2008
 
 
Entity Framework Q&A (May 2008)
Standard Query Operators with LINQ (Mar 2008)
Designing an Entity Model (Feb 2008)
Accessing Data in Mobile Applications (Jan 2008)

2007
Data Binding in WPF (Dec 2007)
SQL Server CTE's (Oct 2007)
.NET 3.5 Language Enhancements (July 2007)
ADO.NET Entity Framework Overview (Jul 2007)
SQL Server Management Objects (Jun 2007)
Gathering RSS Feeds (May 2007)
Disabling Constraints and Triggers (Apr 2007)
Data Bound Applications with ADO.NET and Custom Objects (Feb 2007)
Column Expressions, DataRelations, and Computations (Jan 2007)

2006
RSS Feeds on a Smartphone (Dec 2006)
System.Transactions (Nov 2006)
Reporting controls in SQL Server 2005 Reporting Services (Jul 2006)
Designing Reports with SQL Server Reporting Services 2005 (Jun 2006)
SQL Server 2005 XML support, exception handling, and more (May 2006)
Using XQuery, New Large DataTypes, and More (Mar 2006)
SqlConnectionStringBuilder, DataView, and More (Jan 2006)

2005
DataSet and DataTable in ADO.NET 2.0 (Nov 2005)
The Enterprise Library Data Access Application Block, Part 3 (Oct 2005)
The Enterprise Library Data Access Application Block, Part 2 (Aug 2005)
The Enterprise Library Data Access Application Block, Part 1 (Jul 2005)
XML Features in SQL Server 2000 (Jun 2005)
Data Access Strategies Using ADO.NET and SQL (May 2005)
ADO.NET and System.Transactions (Feb 2005)
Data Source Controls in ASP.NET 2.0 (Jan 2005)

2004
Efficient Coding With Strongly Typed DataSets (Dec 2004)
Updating Data in Linked Servers, Information Schema Views, and More (Nov 2004)
Handling Data Concurrency Using ADO.NET, Part 2 (Oct 2004)
Handling Data Concurrency Using ADO.NET (Sep 2004)
Migrating from ADO to ADO.NET, Part 2 (Aug 2004)
Migrating from ADO to ADO.NET (Jul 2004)
Contrasting the ADO.NET DataReader and DataSet (Jun 2004)
Saving Parent-child Data in a Multitiered App Using ADO.NET (May 2004)
Display and Manage Images in ASP.NET (May 2004)
Creating Audit Tables, Invoking COM Objects, and More (Apr 2004)
Exception-handling Techniques (Mar 2004)
Exploring SQL Server Triggers: Part 2 (Jan 2004)

2003
Exploring SQL Server Triggers (Dec 2003)
SQL Server User-defined Functions (Nov 2003)
Exploring the ADO.NET DataRow (Oct 2003)
Developing with .NET Compact Framework, SQL Server CE, & Replication (Sep 2003)
Managing Hierarchical Inserts in ASP.NET and ADO.NET (Jul 2003)
Techniques in Filling ADO.NET DataTables: Performing Your Own Analysis (Jun 2003)
Techniques for Managing Rowset Paging (Mar 2003)
Expressions in ADO.NET (Jan 2003)


2002
DataRelations in ADO.NET (Nov 2002)
Five Ways to Rev up Your SQL Performance (Jul 2002)
Building a Tiered Web App Using the DataSet and the ASP DataGrid (May 2002)
Establishing Relationships Between Rowsets with ADO.NET (Feb 2002)
Using the ADO.NET DataSet for Multitiered Apps (Jan 2002)

2001
Abstracting ADO.NET (Nov 2001)
ADO to XML: Building a Data Access Tier with DataManager Component (Aug 2001)
Revisiting the Ad-Hoc Data Display Web Application (Jun 2001)
SSL: Protect Your E-Commerce Web Site with SSL and Digital Certificates (Apr 2001)

2000
Managing Session State Across Servers on a Web Farm (Oct 2000)


1999
Using Stored Procedures from ADO 2.1: Enhancing the Refresh Method (Nov 1999)
Automically Backing Up Your Files in Visual SourceSafe (Sep 1999)
Creating HTML Pick Lists with Remote Data Services (May 1999)
Enable Email in Your Web Application (Feb 1999)
Shape Up Your Data: Using ADO 2.0 Hierarchical Recordsets in ASP (Jan 1999)

1998
Ad Hoc Web Reporting with ADO 2.0 (Dec 1998)