Using the Entity Framework in a Layered Architecture
Thursday, July 03 2008 - entity-framework, data-points, wcf, mvp, msdn-magazine - 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.
What's On Your Entity Framework v2 Wish List
Thursday, May 29 2008 - ado-net, entity-framework - 1 comments
I started a "wish list" post in the ADO.NET Entity Framework forums last week. I fed it with a few items to get things going and it has taken off with great input from several people. If you have anything you would like to add to your wish list for features in the next release, please jump in and add your 2 cents.
There have been some great ideas including some of the obvious ones like adding POCO support. improved designer support, and more of an entity model first approach (where we can create entities and have it generate the database from it). But there are also some awesome ideas I never thought of in the list. Check it out and your input.
Entity Framework and LINQ Presentation
Wednesday, May 21 2008 - entity-framework, ado-net, linq, ineta - 0 comments
I had a great time at the INETA sponsored combined Sarasota SQL Server and Sarasota .NET User groups' meeting last Wednesday evening. I presented the Entity Framework and LINQ using the latest bits, which came out 2 days prior to the presentation. It made for some interesting moments as I barely had enough time to convert all of my demos over to the latest bits. Yeah, I know, I should have just went with the old bits, but the smart me was sleeping and the bold me took the wheel :)
I've attached my slide deck and some demo code that I used for the presentation. The code has been converted to work with the Visual Studio and .NET 3.5 SP 1 beta bits. Everything is "as is" as some of the demo code I wrote on the fly at the presentation.
There were about 40 people there for the presentation and it was a very lively and interactive group. A lot of good questions were posed and thought he flow was pretty fast it seemed to be well received.
Entity Framework & LINQ in Miramar, FL
Monday, May 19 2008 - entity-framework, linq - 0 comments
I'll be heading to Miramar, FL on July 8th for the local .NET User Group meeting to speak to the group about the Entity Framework and LINQ. I "hope" the final bits are released by then, but not on July 8th, please (yikes!). I went through a major overhaul of my demonstrations last week when the latest beta bits were released and it was the day before my last presentation on LINQ and the Entity Framework. It went well, but it was a bit too much "last minute" for me. Especially when I am spending every free moment writing my Silverlight book and its examples.
There is a lot to demonstrate .... showing why it exists, how it works, how to use it with a real world application. There are also the discussions of where it is heading, when to use it, when not to use it, and how it compares to existing tools. I often get asked "should I use EF in my app?". The answer always depends of course. But I generally do not encourage people to rip out their existing architecture and replace it with anything unless there is a major benefit that you can receive. The EF is a great tool, no doubt, but it still does not support certain aspects that would make it great (i.e. POCO). Can EF be everything to everyone? No, certainly not. Can EF be a valuable piece of your architecture? Absolutely. Would I jump up and down continuously for a week if they made it work with POCO? HECK YES!
Anyway ... its a good topic and always stirs up a good discussion, which is why I love talking about it. Its not about the model and its not about the data. Its about both, together.
If you are going to be in the area, please stop by. Should be a good discussion in South Florida! Here is the registration link.
Why Use the Entity Framework?
Saturday, May 17 2008 - entity-framework, silverlight, rest, data-services - 6 comments
I've prepared dozens of articles and presentations on the Entity Framework over the past year and a half and the questions always start with "Why would I want to use this instead of XYZ?" LINQ to SQL, a variety of ORM tools, straight up ADO.NET, custom data layers, CSLA.NET and this list goes on and on. This is a great questions and I was glad to see Danny Simmons of Microsoft addresses this today on his blog. Danny mentions the differences between the Entity Framework and a few of these alternatives and specifically points out situations where they don't follow the same music.
The differences between the choices are outlined well in Danny's post. However the key point I want to stress is what Danny calls out in the last paragraph:
"Long-term we are working to build EDM awareness into a variety of other Microsoft products so that if you have an Entity Data Model, you should be able to automatically create REST-oriented web services over that model (ADO.Net Data Services aka Astoria), write reports against that model (Reporting Services), synchronize data between a server and an offline client store where the data is moved atomically as entities even if those entities draw from multiple database tables on the server, create workflows from entity-aware building blocks, etc. etc. Not only does this increase the value of the data model by allowing it to be reused for many parts of your overall solution, but it also allows us to invest more heavily in common tools which will streamline the development process, make developer learning apply to more scenarios, etc. ..."
Basically the Entity Data Models that are built using the Entity Framework are going to be the centerpiece of communications with several technologies. Its not that its better or worse than XYZ, its that it will collaborate better with other tools (some not yet built nor conceived).
Again, from Danny;s post ... "it's the first step in a much larger vision of an entity-aware data platform." I like this ... rolls off the tongue. Think about this example .. Silverlight applications need to communicate with other "places" to get their data. This could be a web service, a REST request, or even a POX (Plain Old XML) stream. Making data available via REST is becoming more abundant ... and with ADO.NET Data Services you can use REST to retrieve entities, because ADO.NET Data Services effectively handles the translation of the REST request to and from the entities in an Entity Data Model. So its a win win situation for Silverlight and for developers since we get to reuse our Entity Data Model and leverage our existing code.
Is it all perfect? Of course not. Does the Entity Framework fit for every situation? Of course not. But one thing is for certain ... Microsoft is making sure its technologies are EF aware.
DevConnections Las Vegas - Nov 2008
Friday, May 16 2008 - devconnections, silverlight, book, entty-framework, enterprise-library - 1 comments
I'll be speaking at DevConnections in Las Vegas this Fall along with others Julie Lerman and Paul Litwin. The 3 topics I will be presenting are:
- Data Access with Silverlight 2
- Integrating Enterprise Library's Data Access Application Block with your Project
- Practical Strategies with the Entity Framework
The past few events have been awesome and getting stronger and more fun each time. If you are planning on attending the conference in the Fall, please stop by and say hi.
My upcoming book tentatively titled Data Access with Silverlight 2 should almost be available by the conference. I am targeting December, but I am hoping I can pull it off for November.
Visual Studio 2008 and .NET 3.5 SP 1 Beta Download
Monday, May 12 2008 - visual-studio, net, entity-framework, linq, sql-server, astoria - 1 comments
Soma announced this morning that Visual Studio 2008 and .NET 3.5 SP 1 is now ready and can be downloaded. This includes several updates, includes support for SQL Server 2008, and has a few new products including the Entity Framework, LINQ to Entities and ADO.NET Data Services (aka Astoria). ScottGu posted some notes regarding what's included in the service pack, as well.
Of course all of this is released 2 days before I have a demonstration on the Entity Framework and LINQ to Entities on Wednesday to the Sarasota .NET and SQL Server User groups. So I have a few modifications to make for my presentations.
I received an error when I first tried to install it. The problem was that the service pack was in conflict with Silverlight Tools Beta for Visual Studio 2008 which I was using to create/edit Silverlight 2 applications. Once uninstalling this i was able to get the service pack to install properly. Scott Gu's post discusses this issue as well as the importance of making sure you install Vista SP 1 first.
Check out ScottGu's post for full details.
Silverlight, WCF and LINQ to SQL
Wednesday, May 07 2008 - silverlight, entity-framework, linq, sql, wcf - 1 comments
I've had some requests lately to write some articles that work with LINQ to SQL. I've ben focusing on the Entity Framework a lot due to its vast nature and that fact that its still relatively unknown to many people. So I am going to work on a LINQ to SQL project that ties into a multi tier model. I am also going to show how this can be hooked into a Silverlight 2 UI that connects through WCF to the lower layers.
I'll probably be demonstrating these first at an event I am trying to set up with Joe Healy of Microsoft in Tampa this coming August. The demos will be ready way before then, but I wanted to have some cool materials for this event. There is no title nor date yet, but once the event is set I will be sure to let blog about it. It should be a great day overall.
I also plan on giving some love to the Entity Framework, regular persistence/mapper models, MVP patterns and more. I just have to find a way to work it all in and still give enough to each topic. Of course, this means all demos are subject to change, but the content will be fresh and cool for certain.
Here is a very poorly and quickly thrown together diagram of one of the demos I am tweaking.
Entity Framework Q&A - Lazy Loading, ObjectContext, and LINQ
Monday, May 05 2008 - data-points, linq, entity-framework - 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.
Projecting with Aggregates in LINQ to Entities
Monday, April 28 2008 - linq, entity-framework, lambda - 1 comments
I'm all for quick and easy examples especially when it comes to LINQ, so here goes one that I get asked a lot. This is a quick example that shows how to grab a few properties from a parent entity and use an aggregate function on the parent entity's children entities. Specifically, this example grabs the OrderID and OrderDate from the Orders entity and then calculates the order total for each order. The sum is calculated by summing the UnitPrice * Quantity in the OrderDetails entity.
// Code below creates a projection containing LCDvar qry = from o in context.Orders where o.Customers.CustomerID == customerIDgroup o by o.OrderID into g
join o2 in context.Orders on g.Key equals o2.OrderID select new {OrderID = g.Key,
o2.OrderDate,
OrderTotal = o2.OrderDetails.Sum(d => d.UnitPrice * d.Quantity)
};
foreach (var orderInfo in qry)
{var msg = string.Format("OrderID={0}, OrderDate={1:d}, OrderTotal={2}",
orderInfo.OrderID, orderInfo.OrderDate, orderInfo.OrderTotal);
Console.WriteLine(msg);
}
Notice the grouping of the orders first. Then the Orders are joined back to the result so we can get the OrderDate property. Then the projection pulls out the Key (the OrderID), the OrderDate, and calculates the OrderTotal using an aggregate and a lambda expression.
Hopefully this will shed some light on this type of projection with LINQ for some.
JohnPapa.NET is Open for BusinRSS
Saturday, April 19 2008 - codebetter, graffiti, devconnections, entity-framework, ssrs, sql-server, linq - 0 comments
No that's not a typo in the title ... it's my poor attempt at dry humor :)
I have had several questions from people over the past few months regarding my noticeable sparseness in blogging at www.codebetter.com, my blogging home for the past 3 years. The truth is that it took me a while to get back to setting up my new blogging home at www.johnpapa.net . I used the various beta versions of Graffiti CMS to get it started and then I recently migrated the site over to the release version of Graffiti. I must say that Graffiti is perfect for my needs. I can consolidate my posts, organize my events, articles, and add some ASP.NET and SilverLight aspects, too.
So what will you find on www.johnpapa.net ? You will find my usual technical posts as well as a listing of all of the articles I have published (the books listing is not there yet) and all of the events I will be speaking at as they get scheduled and confirmed.
Will I still post to www.CodeBetter.com ? Yes, I will still cross post some content to www.CodeBetter.com but the superset of the posts will be on www.johnpapa.net including technical content, reviews, and opinions.
So please add my new site www.johnpapa.net to your aggregated feed list http://feeds.feedburner.com/JohnPapa.
I'll be at DevConnections this coming week in Orlando, so if you are going to be around please stop by one of my sessions on windows mobile development, LINQ, the Entity Framework or SQL Server Reporting Services and say hi!
Entity Framework Setup - Installation Fun!
Saturday, April 19 2008 - entity-framework, edm, devconnections - 0 comments
Yeah, I know its expected that when a product is in beta and its ancillary features are released in a CTP that there will be some "interesting" issues in getting set up. But its getting a bit out of control (in a good way) lately with all of the installations related to the Entity Framework. I had not noticed much until this weekend as I am preparing my laptop for my sessions at DevConnections in Orlando next week.
Here is the list of installations that I had to go through just to get the Entity Framework up and running:
- Key Entity Framework Bits
- Entity Framework Beta 3
- VS 2008 KB 945282 Patch
- EDM Designer Tools CTP 2
- Extras
- Tools
- Samples
There are the bits themselves, then there are several extras from the Data Team which are very useful. Then there are the tools such as the Mapping Helper (very cool indeed) and eSqlBlast (very cool helpful writing Entity SQL). Finally, there are a few examples that are nice to walk through. of course, then there are the dozens of example projects I have built that I need to migrate to my laptop.
Over time these don't seem like much but when I had to install all of these today it struck me on how much is going into the Entity Framework and from so many sources!. I love this stuff!
Promising "Update Model" Feature Additions in Next EDM Release
Saturday, April 19 2008 - entity-framework, edm, net, ado-net - 0 comments
If you have tried the "Update Model from Database" feature in the Entity Framework's EDM tool (latest version is the EDM CTP 2) you probably have noticed that it currently does not fully update the DB model as well as you hoped. I know I got excited when I first saw the feature, but quickly had a let down as I knew I had to wait til the next release to get more out of this feature. This month Noam Ben-Ami gave us a preview of some of the new features that will be in the next release of the EDM. You definitely want to check this out.
I am thrilled to see that the Update Model from Database feature will not remove items from the conceptual model. Though instead of simply showing errors, I would not mind it asking me with some type of wizard that prompts me with suggestions. For example, when a column has been removed from a table in the database it would be awesome if a list of issues was presented and along with options to take action (such as remove property from the entity and refactor). yeah, yeah, I know its being picky :)
I also love how its smart enough to detect that a hierarchical relationship in the conceptual model may represent multiple tables in the the database. Its getting much closer!!!
EntityBag Modes with the Entity Framework
Friday, April 18 2008 - entity-framework, entitybag, devconnections, ado-net - 0 comments
I've been using the EntityBag concept that Danny Simmons has been posting for a while now. One of the neat aspects of the EntityBag is its automatic mode settings. As I was explaining this to someone this week (as a precursor to my 2 Entity Framework DevConnections talks next week in Orlando), it occurred to me to create a small table explaining the highlights of the modes. So here is the 20,000 foot view of the modes of an EntityBag. You can find more about the EntityBag and its modes on Danny's blog.
Next up, Orlando DevConnections!
Tuesday, April 08 2008 - entity-framework, mobile, net, devconnections - 0 comments
DevConnections in Orlando is just around the corner and I'll be there presenting 4 sessions on mobile development, the Entity Framework and SQL Server. So much has changed with these technologies in the past few months so I have all new code samples for new techniques using the latest bits, especially with the Entity Framework. if you are going to be at DevConnections in April in Orlando, please stop by one of my sessions and say hi.
Here are the 4 session abstracts:
VMD302: Data Access Techniques and LINQ in Mobile Applications
John Papa
Data access layers, domain entities, and databases are all integral components of dealing with data in an enterprise application. Mobile applications also rely heavily on these types of data vehicles and stores. This session will delve into different ways of handling data in mobile applications using ADO.NET objects and domain entities. I will demonstrate different data binding techniques in mobile applications using both domain entities and DataSets as well as techniques using LINQ to interact with data on a mobile device.
VDA203: Getting Started with the Entity Framework
John Papa
The Entity Framework can be used to architect applications against a conceptual model that is mapped to the logic model. The Entity Framework has many components including EntityClient, Entity SQL, Object Services, the Entity Data Model, and LINQ to Entities. This session will discuss the architecture of the Entity Framework and explain the roles of each of its different components. It will also demonstrate how to write queries using the different options as well as how to evaluate which options within Object Services to use or if to use the EntityClient provider directly.
VDA202: Customizing Entity Data Models in the Entity Framework
John Papa
Designing the Entity Data Model with the Entity Framework is a critical aspect in developing an architecture. Once the model has been created it is beneficial to know how to customize the model to adapt to the business problems. This session will explore the different XML files that map the objects to the database schema and show how to modify them when needed. I will explain how you can design an object model with the Entity Framework using both the Entity Data Model Wizard as well as by manually editing the XML files. I will demonstrate how to implement inheritance, how to merge multiple entities within a conceptual model, how to take advantage of features such as conditions in the mapping layer, how to implement complex types, and how to hook into stored procedures. This session will demonstrate how to interact with the conceptual model using EntityClient, Entity SQL, and LINQ to Entities to perform queries and make updates to a database.
Standard Query Operators with LINQ
Friday, April 04 2008 - entity-framework, linq, data-points, msdn - 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.
Invalid References in Entity Framework
Wednesday, January 30 2008 - entity-framework - 0 comments
We all make mistakes ... I know I certainly do. Today I made one that only set me back about 10 minutes ... but I admit I felt silly after I realized what I did wrong. Today I created a new VS 2008 project, added an Entity Data model (aka EDMX file) to the project, and began setting up my EDM. When i went to build the project I received a ton of errors about invalid references. So I checked my references folder and bam! ... several dll's were marked is invalid.
The quick and easy solution to this problem was that I forgot to set the target framework of my project to .NET Framework 3.5.
Once this is done everything is happy as Ferris Bueller in a parade.
Designing an Entity Data Model
Sunday, January 20 2008 - entity-framework, linq, data-points, edm - 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.
New EF CTP! ADO.NET Entity Framework June 2007 CTP is Available
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 4 comments
The ADO.NET team has released the latest bits for the ADO.NET Entity Framework with the June 2007 CTP. There are samples on CodePlex, too. It claims many changes and support for a lot of new features ... I grabbed this partial list from their post:
- Changes in:
- Object Services
- Query
- Entity Client
- the Entity Data Model Wizard in Visual Studio
- no more default constructors in code-generated classes
- improvements to stored procedure support
- New Features:
- IPOCO
- detaching from long-running ObjectContext instances
- multiple entity sets per type
- support for referential integrity constraints
- span support
- transactions
- serialization
Notice the IPOCO support. This is something that is a step in the right direction for getting the entities in the EDM to move towards full POCO. I am downloading the bits now and can't wait to unwrap the candy!
Data Access "Practically Done"
Friday, February 01 2008 - net, ado-net, entity-framework, linq, ent-lib, sql - 3 comments
I will be kicking off my move to South Florida in a few weeks with a 1 day event for the “Practically Done” event series. On Wednesday August 1st and on Saturday August 4th I will be presenting “Data Access Done Right”, a full day event in Orlando.
Register here for Wednesday, August 1st – 9am to 5pm
Register here for Saturday, August 4th – 9am to 5pm
I encourage you to bring your laptops as code samples will be given out to all attendees at the beginning of the event. You can follow along with the samples as they are being discussed and demonstrated. Seating is limited for this event and discounts are available for early sign ups.
| "Practically Done" .NET Events | |
| Not everybody can take a week off from work to attend a technology conference that may be thousands of miles away and cost a fortune. Most of the time, those conferences cover technologies that won't be released for months or years, anyway. ASPSOFT recognizes the need for local, single day workshops that focus on current .NET technologies that you can apply to your projects today. "Practically Done" .NET Events feature:
Data Access Done Right Speaker: John Papa Location: Orlando, FL Data access is an integral component of an enterprise application’s architecture. Retrieving data, saving data, passing data between tiers, presenting data to a user interface, and managing transactions are all important pieces of a data access strategy. In this “Practically Done” workshop, Microsoft MVP John Papa will show you how to apply these techniques in your multi-tier applications today using Visual Studio 2005. The topics that will be covered in detail are:
| |
Entity Framework and its Tools in First Half of 2008
Friday, February 01 2008 - ado-net, entity-framework, linq - 2 comments
As I noted earlier, my latest article in MSDN Magazine was just posted a few days ago. If you visited it early on you might have missed the comment from the edtitor which reads:
[ Editor's Update - 6/19/2007: The ADO.NET Entity Framework and Tools will ship during the first half of 2008 as an update to the Visual Studio 2008 release.]
We were told the tools would ship later, so this just confirms the plans for the EF and its tools to be available next year. I'll be chomping at the bit to use it and giving as much feedback as I can to the team as I can. They seem dedicated to making a great product that we can use in DDD.
ADO.NET Entity Framework Overview
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 0 comments
My July 2007 Data Points column has been posted to the MSDN Magazine web site. This edition is titled "ADO.NET Entity Framework Overview".
I wrote this using the March CTP and then revised it using the Orcas Beta 1, so the code included works in the most recently available bits. Knowing that changes are on their way, I tried to focus the article on the concepts and technical aspects of the EF that make ups its foundation. The components such as Object Services, Entity Client, and LINQ to Entities will evolve but are fairly well baked. Aspects I expect to change (although I have no evidence to support it) are the way the entities are implemented. For example, I expect they may evolve into more of a POCO style with no interface nor base class required. This topic has been beaten pretty hard, so I won't add anything further to it for now since I agree with most of what has already been blogged about. There is one piece which I know is on its way, however late to the game it may be ... the EDM Designer.
Anyway ... this article is an overview of how the EF is structured and how its pieces work. I inlcuded some examples as well. It was difficult to keep the word count down on this one ... my first draft had over 7000 words in it (supposed to be about 3000). So we cut it down to a reasonable and digestable size. I hope you enjoy it!
Entity Framework: CSDL, MSL and SSDL Schemas
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 0 comments
Due to the lack of a designer and because I am very curious, I’ve been digging through the XML for the CSDL, MSL and a little bit into the SSDL schemas for the Entity Framework’s Entity Data Model. Even if you are waiting for the Designer to be released (date TBD) it cannot hurt to get familiar with these XML file structures. For example, the MSDL’s schema supports the following for the mapping Conditions:
<!-- Type for Condition Element-->
<xs:complexType name="TCondition">
<xs:attribute ref="tns:Value" use="optional" />
<xs:attribute ref="tns:Name" use="optional" />
<xs:attribute ref="tns:ColumnName" use="optional" />
<xs:attribute ref="tns:IsNull" use="optional" />
</xs:complexType>
Currently the conditions in mapping only allow you to compare a column to a scalar value or to check for NULL. You can create multiple conditions, which will create an AND situation. However you cannot combine the conditions with OR’s (i.e. you can’t say get all orders > $10,000 or orders < $100). In fact, nor can you compare values at this point (i.e. < ). These features are surely going to be in future versions, though.
By having the XSD’s for the CSDL, MSL AND SSDL you can explore what options are available even if the intellisense is not working in the latest CTP J (which has happened to me at times). For example, I noticed that complex properties are in the schema, however they are not fully supported at this time. But at least this gives me a glimpse at what might be supported in the future.
I open the XSD’s in Visual Studio.NET Orcas, but of course you can use other tools like XML Spy. Here is a snapshot of the TableMappingFragment’s schema from the MSL file:
If you are looking for the XSD’s, you can find them in the March Orcas CTP located at this folder:
C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas
And the file names are:
- CSDLSchema.xsd
- CSMSL.xsd
- SSDLSchema.xsd
Entity Framework Thoughts
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 13 comments
I agree that there is quite a bit of work to do yet with the Entity Framework. Earlier today Scott posted his thoughts on the challenges that the Entity Framework faces. He makes some good points which really show how the approach to application development greatly influences which tools and development strategies developers will choose. I agree that applications have a better chance to succeed when they are "business rule" driven.
I prefer to build a data model and a business model together, not one before the other. In its current state the Entity Framework can be generated from an existing data model (or can be created by hand with XML). The data team at Microsoft knows this is a limitation and is working on solutions to make building and tweaking entities, mapping the conceptual model to a logical model, and overall design of the EDM much more fluid. I am very excited about seeing what they produce on this end.
Building off of the example that Scott worked, assume you have an entity that you are working with and realize that you need to add a new property (or field) to it to establish a business rule (or to write a test if you are using TDD). You want to add the field or property to the entity and keep moving along with your business rule (probably using Resharper or the like to create the field/property combination). The idea is to keep your brain patterns flowing with the business rule and not to step outside of tat to implement a new field/property and populate it. You want to create the additional property, use it in your code, and map it to the models quickly.
With the Entity Framework in its current state you could add a new partial class and add the field and property to it, but then you are deviating from the EDM with a field that you will eventually want to persist in the database anyway. Another option with the Entity Framework is to add the property to the conceptual model and mapping it to a database field (that you must create). This is an option that makes sense but is the most difficult to implement at this time. I believe this is one area where the Entity Framework has room to grow and the data team can add more value to the development community: Having a way to easily amend business entities, have it flow through the conceptual model ,and map them to a logical model to the database.
There is a lot left to work out and the more people who use the Entity Framework, participate in the forums, test the CTP’s, and provide feedback where they can, the better the end result will be. I believe that the data teams at Microsoft are absolutely committed to this technology and I am personally very excited about the Entity Framework ….. more excited than I have been about a technology in a long, long time.
Stored Procedures and CUD (minus the R) in the Entity Framework
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 0 comments
The Data Access Team published a great post that has some superb explanations on how to make the Entity Framework use stored procedures for inserts, udpates and deletes. (It does not yet support stored procedures for retrieving data.) Obviously there are pieces missing, as Shyam states (such as retrieving data via sprocs), but to see CUD (minus the R) working in the EF with sprocs is great.
One knock I can already hear though is how people will have to change the existing sprocs. Specifically in the example where the additional parameter must be added to support the EF's determination of which entities/sprocs to execute in which order. Obviously it would be better if a future evolution could do without this.
Fantastic to see sproc support born in the Entity Framework!
On a related note, I am having a heck of a time trying to get an overview of ADO.NET Orcas to fit into a publishable article. There is just sooooo much to it and so little space to write about it. I could go on for days on this topic :)
LINQ to Entity Samples added to 101 Samples!
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 1 comments
Earlier in March I posted that some samples intended for use with the March CTP of Orcas were available for download. These samples replace the samples that are linked from the MSDN docs in the CTP. One thing these samples lacked was the LINQ to Entities samples. Today, Charlie Calvert posted a link to updated samples that include LINQ TO Entities samples inside the SamplesQueries example project. Inside the SamplesQueries project you will find a 101 LINQ to Entities samples.
This is great news! Previously there were tons of examples in this project for LINQ to SQL, LINQ to XML, LINQ to Objects and LINQ to DataSets. With the additin of LINQ to Entities, it means I have plenty of material to play with and keep my head buried in ADO.NET and the Entity Framework.
Entity Framework and Object Services Primer
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 0 comments
As I am sure you have read by now, the Entity Framework is a huge leap forward in the next iteration of ADO.NET in Orcas. Currently the implementation has a conceptual layer represented by a CSDL file. This CSDL file contains the XML that represents conceptual model (the objects). The conceptual layer is mapped to the database through a series of lower layers (the Mapping and the Source). The Source is represented by a SSDL file which contains XML that represents the database schema. The MSL file contains the XML that maps the CSDL to the SSDL. All 3 of these files can be generated using the EDM Model Wizard in the Orcas Feb/March CTP.
Once the model has been generated (or created by hand), the data can be manipulated and interrogated through the conceptual model. Thus a level of abstraction is created where an application can interact with data through an object model that is mapped to the underlying data source. LINQ to Entities or Entity SQL can be used to interact with the EDM. LINQ to Entities is great when you can define your query expressions at design time and enhance them with parameters. Entity SQL can also be sued to achieve the same goals, however since Entity SQL is string based it can support more dynamic queries where queries can be built on the fly.
There is quite a bit to chew with the Entity Framework, more than enough for a entire series of articles. And I have not even touched on the other ADO.NET components such as LINQ to SQL or LINQ to DataSets, much less the designers, LINQ to objects, LINQ to XML, EntityClient and much much more.
It is an exciting time to be involved with data access technologies! And some unforeseen changes are yet to come as many have already experienced the changes through the CTP’s of LINQ and Orcas. But it seems evident that the data access team is making its biggest change to data access in a very long time.
Updated Samples for Orcas March 2007 CTP
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 0 comments
Charlie Calvert has posted some samples intended for use with the March CTP of Orcas. These samples replace the samples that are linked from the MSDN docs in the CTP (which is good since I have had mixed result wth them so far). Charlie also posted a video on the samples here that helps explain them.
Entity Framework Terminology
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 0 comments
I have some articles to write on the Entity Framework and LINQ to ADO.NET, so I will be busy in the depths of EF for a while. I have been spending the past few days immersing myself in the Orcas March CTP. While there are features I am still longing for (such as the EDM Designer) this is the most EF & LINQ complete CTP in a long time. While the MSDN Documentation is not complete by any means, there is some great information in there. For example, I found this fantastic page in the help docs that is a glossary of the Entity Framework terminology. I pulled this directly from their documentation, which you can find at this link (ms-help://MS.MSDNQTR.v90.en/MS.MSDN.v90/MS.VisualStudio.v90.en/WD_ADONET/html/fa2a1bd1-6118-487b-8673-eebc66b92945.htm ) in the March CTP's help docs. This is a great reference to lean on when learning the EF ... kudos to the data team for creating and including this information in the CTP.
Entity Framework terminology:
alias
An attribute of the Schema element in CSDL and SSDL schemas that can be substituted for the full namespace to shorten element references in the schema.
association
The definition of a relationship between entity types.
association set
A logical container for instances of associations of the same type.
base type
A parent type or super-type in the EDM from which derived types inherit some of their properties.
complex type
An entity type whose properties have internal properties. Used as a property of an entity type or of another complex type.
conceptual schema definition language (CSDL)
XML-based dialect used to define the entity types, associations, entity containers, entity sets, and association sets of a conceptual model.
conceptual model
Abstract specification for the entity types, associations, entity containers, entity sets, and association sets comprising an application domain.
constraint
Restricts the possible values of a property and ensures that a value is valid.
container
A logical grouping of entity and association sets.
degree
The number of entity types in a relationship. Relationships are classified as unary, binary, ternary, or n-ary.
direction
Refers to the asymmetrical nature of some associations. Direction is specified with FromRole and ToRole attributes of ReferentialConstraint elements in entity data models.
end
A participating entity in an association.
entity
An instance of an entity type.
EntityClient
A storage-independent ADO.NET data provider containing classes such as EntityConnection, EntityCommand, and EntityDataReader. Works with Entity SQL and connects to storage specific ADO.NET Data Providers, such as SqlClient.
entity container
Specifies the sets of entity types and associations that will be available in a specified namespace.
Entity Data Model (EDM)
A system for defining application data as sets of entities and relationships.
Entity Framework
A set of technologies that supports development of data-oriented software applications by allowing developers to work with conceptual models that are mapped to logical schemas in data sources.
entity-relationship model
A data model that uses relationships between entities as the basis for describing application data schemas.
entity set
A logical container for entities of the same type, mapped to tables in a database.
Entity SQL
A storage-independent dialect of SQL that works directly with conceptual entity schemas and that supports entity data model features such as inheritance and relationships.
entity type
A named set of properties representing a top-level item in a data model.
enumeration
A simple type whose single value is selected from a specified set of options.
facet
A constraint, such as Nullable, MaxLength, or Precision, that limits the allowable values for a property.
helper method
User-defined operations implemented in partial classes that add functionality to objects generated from entity data models.
key
The attribute of an entity type that specifies which property or set of properties is used to identify unique instances of the entity type.
language integrated query (LINQ)
A query syntax that defines a set of query operators that allow traversal, filter, and projection operations to be expressed in a direct, declarative way in C# and Visual Basic.
LINQ to Entities
The use of language integrated query operators with objects representing a conceptual model.
mapping
A set of correspondences between items in a conceptual model and items in a storage model.
mapping specification language (MSL)
An XML-based dialect used to map items defined in a conceptual model to items in a storage model.
metadata
Data used to describe the structure of other data, including the SSDL XML file, which describes the structure of data in a data store.
Metadata Workspace
A class that represents the metadata runtime service component that provides support for retrieving metadata.
multiplicity
The number of entities that can exist on each side of a relationship.
navigation property
A property of entity types that uses an association to reference related entities.
object services
Services provided by the Entity Framework to classes generated from a set of metadata.
object context
A base class that provides object services such as tracking and saving changes, and that contains a connection to the underlying data store.
referential constraint
An element of an SSDL entity data model that specifies the direction of an association with FromRole and ToRole attributes. Corresponds to a CSDL navigation property.
relational model
The logical model used to define the tables, columns, and constraints in a database.
relationship
A logical connection between entities.
role
The name given to each end of an association to clarify the semantics of the relationship.
simple type
Primitive type used for defining properties in entity data models.
store schema definition language (SSDL)
XML-based dialect used to define the entity types, associations, entity containers, entity sets, and association sets of a storage model, often corresponding to a database schema.
table-per hierarchy (TPH)
A method of modeling a type hierarchy in a database that includes the attributes of all the types in the hierarchy in one table.
table-per-type (TPT)
A method of modeling a type hierarchy in a database that uses multiple tables with one-to-one relationships to model the various types.
XML (simple type)
Can contain well-formed XML or valid XML data. The facets of this type control which kind of XML data can be contained within it.
Entity SQL & the EntityClient Provider in ADO.NET vNext and Orcas
Friday, February 01 2008 - net, sql, ado-net, entity-framework, linq - 0 comments
If you watch the ADO.NET team’s blog then you may have seen the post from today from Zlatko Michailov (Program Manager, ADO.NET). Here are the highlights from his post:
In this Entity SQL (eSQL) post he discusses:
- what Entity SQL is
- a brief example of how to use it to retrieve a hierarchical set of parent-children data
- (Categories and their respective Products)
- No join syntax necessary!
- an example Connection String for the EntityClient provider
- how the EntityClient returns a common DbDataReader so we can create and fill our own classes from it
- that this uses the well known ADO.NET pattern of Connection, Command, Parameter and DataReader classes
- class names are prefixed with “Entity”
- that the next Orcas release should have this functionality
- however, he explains that it will not yet be able to use DML (aka no INSERT, UPDATE, DELETE)
There are a lot of features I am looking forward to in the next Orcas CTP (hopefully a February CTP and not a March one). I have high hopes for the future with features like Entity SQL, LINQ to SQL, LINQ TO DataSet, EDM, and LINQ to Entities. Kudos to the ADO.NET team for taking this direction!
Interesting Orcas & LINQ Links
Friday, February 01 2008 - net, ado-net, entity-framework, linq - 3 comments
Here are a few good links to Orcas material (some old and some new). There is a lot of good and bad material out there with LINQ. These are some of the better ones that I have found. Feel free to comment about any other good LINQ / Data Access related links.
Downloads:
&mi







