<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Entity Framework Design : Linq to Sql</title><link>http://blogs.msdn.com/efdesign/archive/tags/Linq+to+Sql/default.aspx</link><description>Tags: Linq to Sql</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>LINQ to SQL to Entity Framework conversion template</title><link>http://blogs.msdn.com/efdesign/archive/2009/08/13/linq-to-sql-to-entity-framework-conversion-template.aspx</link><pubDate>Fri, 14 Aug 2009 00:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9868818</guid><dc:creator>efdesign</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9868818.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9868818</wfw:commentRss><description>&lt;P&gt;Many customers have asked us how to port a LINQ to SQL application to the Entity Framework. In order to make this process easier, we have developed a metadata conversion template. &lt;/P&gt;
&lt;P&gt;This template converts LINQ to SQL metadata (.dbml) to metadata compatible with Entity Framework (.edmx). While not a complete solution to the conversion problem, it is a useful first step. The template available for download is still in the development stage, and any feedback you have on the user experience, additional features, or any other aspect of the conversion would be greatly appreciated. &lt;/P&gt;
&lt;P&gt;The T4 template is intended to convert simple valid .dbml files to .edmx files. All of the basic elements of the .dbml file are mapped to their .edmx counterparts. For instance, Tables are mapped to EntitySets and Types are mapped to EntityTypes. Additionally, stored procedures (including customized insert, update and delete stored procedures) and associations are also converted. &lt;/P&gt;
&lt;H4&gt;Downloading the Metadata Conversion Template&lt;/H4&gt;
&lt;P&gt;Included in the zip file is a .vsix installer for the T4 Conversion Template. Also included is detailed documentation for the template. VS 2010 Beta 1 is required.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/efdesign/attachment/9868818.ashx" mce_href="http://blogs.msdn.com/efdesign/attachment/9868818.ashx"&gt;Download the Template&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;&lt;/H4&gt;
&lt;H4&gt;Walkthroughs&lt;/H4&gt;
&lt;P&gt;Two walkthroughs have been written to help guide users through the conversion process. The walkthroughs both take the form of unit tests which can be run against the existing LINQ to SQL metadata and the Entity Framework metadata produced by the conversion template. Each walkthrough contains detailed instructions on how to convert the existing LINQ to SQL project to Entity Framework using the Conversion Template. The first is the Widget Factory walkthrough, which shows a basic conversion. The second (CustomCUD) shows how to convert a LINQ to SQL project which uses custom insert, update and delete stored procedures. The walkthroughs are available individually. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/efdesign/pages/widget-factory-walkthrough-for-the-linq-to-sql-to-entity-framework-metadata-conversion-template.aspx" mce_href="http://blogs.msdn.com/efdesign/pages/widget-factory-walkthrough-for-the-linq-to-sql-to-entity-framework-metadata-conversion-template.aspx"&gt;Widget Factory Walkthrough&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/efdesign/pages/custom-cud-walkthrough-for-linq-to-sql-to-entity-framework-metadata-conversion-template.aspx" mce_href="http://blogs.msdn.com/efdesign/pages/custom-cud-walkthrough-for-linq-to-sql-to-entity-framework-metadata-conversion-template.aspx"&gt;Custom CUD Walkthrough&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;&lt;/H4&gt;
&lt;H4&gt;Caveats and Known Issues&lt;/H4&gt;
&lt;P&gt;Because the Conversion Template is still under development, there are a number of open issues and unimplemented features. A more comprehensive list can be found in the documentation included with the template installer. &lt;/P&gt;
&lt;P&gt;· Inheritance: Inheritance has not been fully implemented. While the template may work in some basic cases, this aspect of the conversion remains an open issue.&lt;/P&gt;
&lt;P&gt;· Independent Associations: Foreign-key associations will not be available until .NET 4.0 Beta 2, so the current version of the template will only work with the "UseIndependentAssociations" flag set to true.&lt;/P&gt;
&lt;P&gt;· Property Attributes: not all of the property attributes (such as "Unicode" and "FixedLength") are converted because these are not explicitly present in the .dbml file.&lt;/P&gt;
&lt;H4&gt;Feedback&lt;/H4&gt;
&lt;P&gt;We are interested to hear any comments you have about known issues, additional feature requests, suggestions for additional walkthroughs or any other aspect of the conversion process.&lt;/P&gt;
&lt;P&gt;Thanks, &lt;BR&gt;&lt;STRONG&gt;Christina Ilvento &lt;BR&gt;&lt;/STRONG&gt;Developer, &lt;BR&gt;Entity Framework Team&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9868818" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/efdesign/attachment/9868818.ashx" length="45365" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Linq+to+Sql/default.aspx">Linq to Sql</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Templates/default.aspx">Templates</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Migration/default.aspx">Migration</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category></item><item><title>Foreign Keys in the Conceptual and Object Models</title><link>http://blogs.msdn.com/efdesign/archive/2008/10/27/foreign-keys-in-the-conceptual-and-object-models.aspx</link><pubDate>Mon, 27 Oct 2008 19:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9018535</guid><dc:creator>efdesign</dc:creator><slash:comments>36</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9018535.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9018535</wfw:commentRss><description>&lt;P&gt;If you are reading this, you have probably heard by now about the so called impedance mismatch between the relational world and the object world – and there are a number of concepts in the relational database that don’t translate easily to corresponding concepts supported by the object oriented paradigm. One of these factors that is particularly interesting (and often controversial) is the concept of Foreign Keys and whether or not they belong in your conceptual/object model.&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;FKs are used to represent relationships in the database – but with objects, the natural way to represent relationships is through real references between objects. So as an object relational mapping platform, should a product support one or the other, or both?&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;I think most will agree that there is tremendous value in supporting relationships in the model as first class references between objects.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;What are some of the issues with supporting both foreign keys and references in the same model? We could take a real world example i.e. LINQ to SQL and its foreign key support to look at some of the benefits as well as the downsides to having foreign keys.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;H3&gt;Foreign Key Support in LINQ to SQL&lt;o:p&gt;&lt;/o:p&gt;&lt;/H3&gt;
&lt;P&gt;LINQ to SQL takes the simplistic approach of making foreign keys available to you as a scalar property in your entities. In essence, LINQ to SQL allows you to write code dealing with relationships like so:&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN class=type&gt;Product&lt;/SPAN&gt;&amp;nbsp;chai = db.Products.Where(p =&amp;gt; p.ProductName == &lt;SPAN class=stringliteral&gt;"Chai"&lt;/SPAN&gt;).Single(); &lt;BR&gt;chai.CategoryID = 1; &lt;BR&gt;db.SubmitChanges(); &lt;/DIV&gt;
&lt;P&gt;This is possible in LINQ to SQL mainly because foreign keys are somewhat central to the way relationships are implemented and supported. &lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;This particular example achieves something quite powerful, however - here you have essentially changed the category that the product Chai belonged to without ever having to query and materialize the new category that you associated Chai with.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;However, LINQ to SQL also allows you to do this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN class=type&gt;Product&lt;/SPAN&gt; chai = db.Products.Where(p =&amp;gt; p.ProductName == &lt;SPAN class=stringliteral&gt;"Chai"&lt;/SPAN&gt;).Single(); &lt;BR&gt;&lt;SPAN class=type&gt;Category&lt;/SPAN&gt; beverages = db.Categories.Where(c =&amp;gt; c.CategoryName == &lt;SPAN class=stringliteral&gt;"Beverages"&lt;/SPAN&gt;).Single(); &lt;BR&gt;chai.Category = beverages; &lt;/DIV&gt;
&lt;P&gt;We have been considering for a while about whether or not we want to include support to allow you to expose foreign keys in the model. Let’s see what you gain / lose by having foreign keys in the model.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;One of the fundamental issues is that the simple foreign key concept that works so well in the relational model isn’t sufficient to represent relationships in the conceptual model. In the Entity Framework, a relationship is a first class concept that must be mapped to any set of columns in the database – and the important thing here is that these columns don’t have to represent relationships on the database by the means of FKs and constraints. Another point to note is that in the Entity Framework, relationships are always comprised of two ends, and are bi-directional unlike foreign keys.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;What does all of this do for the model?&amp;nbsp; This opens up possibilities, such as Referential Integrity constraints that are represented in the EDM even though they may not necessarily be present on the relational model in the store. Bi-directional nature of the relationships makes it possible for you to navigate in both directions along a relationship in a way that is generally not possible with a simple FK.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;Foreign Keys are not without value, however. An interesting challenge for us is to figure out how to bring the best aspects of Foreign Keys into the Entity Framework without compromising the richness and flexibility that relationships bring to the table.&amp;nbsp; Let’s look at the upside and the downsides of plain relational foreign keys:&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;H3&gt;Benefits of Foreign Keys&lt;o:p&gt;&lt;/o:p&gt;&lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;Keeps it simple (for the simple cases)&amp;nbsp; and allows you to deal with relationship like you deal with them in the database&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;
&lt;LI&gt;Technically, you can update relationships without having both ends loaded/materialized. This is however in reality not always interesting since you will likely load both ends but this feature is definitely useful.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H3&gt;Disadvantages of Foreign Keys in the Model&lt;o:p&gt;&lt;/o:p&gt;&lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;It is a part of the impedance mismatch problem.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;
&lt;LI&gt;It doesn’t allow the concepts that you would expect from relationships in objects (easily getting from one end to the other) for instance.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;
&lt;LI&gt;Having foreign keys as well as object references for relationship navigation presents the problem of two different artifacts representing relationships – this introduces complexity and now you have to make sure that you keep these two in sync.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;So where do you stand? Do you like foreign keys or do you think they are evil? Would you like to see Foreign Keys exposed in the model, and if they are available in your object model, would it be sufficient if they were read-only?&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;Let us know!&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Calibri size=3&gt;&lt;STRONG&gt;Faisal Mohamood&lt;/STRONG&gt;&amp;nbsp; &lt;BR&gt;Program Manager, &lt;BR&gt;Entity Framework Team&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Calibri size=3&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;FONT face=Calibri size=3&gt;this post&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9018535" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/ObjectServices/default.aspx">ObjectServices</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Linq+to+Sql/default.aspx">Linq to Sql</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item></channel></rss>