<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jason Rowe &#187; Entity Framework</title>
	<atom:link href="http://jasonrowe.com/category/entity-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonrowe.com</link>
	<description>enjoying the web</description>
	<lastBuildDate>Tue, 03 Jan 2012 02:03:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Top 5 Features of Code First Entity Framework CTP4</title>
		<link>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=top-5-features-of-code-first-entity-framework-ctp4</link>
		<comments>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 16:19:26 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/</guid>
		<description><![CDATA[&#160; The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release.&#8230;]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>  <p>The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release.</p>  <ol>   <li><strong><em>Less code and fewer Concepts.</em></strong> The coolest part is the use of convention over configuration. See the <a href="http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4piwalkthrough.aspx">Productivity Improvements</a> walk through and <a href="http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx">Conventions for code first</a>. I like the extra touch that DbContext&#160; will create the database for you if you want. No code to write. Just use the default CreateDatabaseOnlyIfNotExists. </li>    <li><em><strong>Simplified Database Experience.</strong></em> With the introduction of DbContext and DbSet. EF now takes care of database provisioning, schema creation and connection management. Nice! My favorite part is the Interface IDbConnectionFactory to allow creation of your own conventions. </li>    <li><strong>Backwards Compatible.</strong> Yes, this is a feature when it comes to CTP’s and Betas. Some projects might just throw stuff away or completely change things on you. EF allows you to still use ObjectContext or <a href="http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx">Data Annotations</a> for advanced scenarios where common conventions don’t work for you. </li>    <li><strong>Simplified Configuration Experience.</strong> As I mentioned you can use annotations for this but you also have another cool option. DbContext includes a virtual method that can be overridden to do configuration right in the class. This means no need for separate configuration classes now. I definitely like having it all in one place. Much cleaner and easy to read. </li>    <li><strong>Testability </strong>IDbSet&lt;TEntity&gt; allows you to define an interface that can be implemented by your derived context. This allows the context to be replaced with an in-memory test double for testing. </li> </ol>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework &#8211; Code Only Looking Good</title>
		<link>http://jasonrowe.com/2009/12/11/entity-framework-code-only/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=entity-framework-code-only</link>
		<comments>http://jasonrowe.com/2009/12/11/entity-framework-code-only/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 04:53:36 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[.net4]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=765</guid>
		<description><![CDATA[The release described in this post is no longer current. Entity Framework 4.1 RTW is now available. I&#8217;ve been hearing rumors Entity Framework (EF) is more robust now. I did a few searches and found the latest version EF CTP2.&#8230;]]></description>
			<content:encoded><![CDATA[<strong>

<blockquote>
<p>
<font color="#ff0000">The release described in this post is no longer current. </font>
</p>

<a href="http://blogs.msdn.com/b/adonet/archive/2011/04/11/ef-4-1-released.aspx">
<font size="5">Entity Framework 4.1 RTW</font>
</a>
<font color="#ff0000" size="5">is now available</font>.
</blockquote>

</strong>
<br />

I&#8217;ve been hearing rumors Entity Framework (EF) is more robust now. I did a few searches and found the latest version <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=13FDFCE4-7F92-438F-8058-B5B4041D0F01&#038;displayLang=en">EF CTP2.</a>  I was happy to find EF has a &#8220;code only&#8221; method for generating the database schema and a good take on configuration. 

If you are intrested in the code only method check out this <a href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx">walk through</a>.  I went through it and built my own application to get a handle on this new feature. Here were the steps I took to get up and running.  You will need Visual Studio 2010, SQL, and CTP2 version of EF.

<strong>1)</strong> Install <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=13FDFCE4-7F92-438F-8058-B5B4041D0F01&#038;displayLang=en">CTP2 Entity Framework Preview 2</a>

<a href="http://jasonrowe.com/2009/12/11/entity-framework-code-only/ctp2-2/" rel="attachment wp-att-792"><img src="http://jasonrowe.com/wp-content/uploads/2009/12/ctp21-300x235.PNG" alt="ctp2" title="ctp2" width="300" height="235" class="alignnone size-medium wp-image-792" /></a>

<strong>2)</strong> Create a new class library project in your solution. This will be for your objects that will get mapped to the database.  I named mine &#8220;UserSchema&#8221;.  In this project you are just creating normal classes without any references to EF.  Below are the two classes I used for testing.  Notice they have no meta tags or any other tags that would be EF specific.

<pre class="brush: c#; ">

   public class Profile
    {
        public Profile() { }
        public int ID { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string PermaUrl { get; set; }
        public DateTime Created { get; set; }
        public DateTime? LastSeen { get; set; }
    }

    public class User
    {
        public User() { }
        public int ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string UserName { get; set; }
        public string Password {get; set;}
        public ICollection&lt;profile&gt; Profiles { get; set; }
    }

</pre>

<strong>3)</strong> Next create a new class project in your solution for your EF models.  I called mine UserManager.Model.  I think it is good to make a seperate project as this is going to setup all your class context for connecting to EF. You will also need to add a project reference to the project that has your objects which you want to be mapped in the database and a reference to Microsoft.Data.Entity.CTP and System.Data.Entity.

<pre>
public class UserModel : ObjectContext
    {
        public UserModel(EntityConnection connection)
            : base(connection)
        {
            DefaultContainerName = "UserModel";
        }

        public IObjectSet<user> User
        {
            get { return base.CreateObjectSet</user><user>(); }
        }

        public IObjectSet<profile> Profiles
        {
            get { return base.CreateObjectSet</profile><profile>(); }
        }
    }
</profile></user></pre>

<strong>4)</strong> Create a new console application to automatically generate your database.  I called mine &#8220;UserManager.GenerateDatabase&#8221;.  This is the application that will use the object context to autogenerate the database. You can also do specific table configuration and other initialization.  You can use a RegisterConfigurations method.  The walk through above goes into more detail on that.

<pre>
var builder = new ContextBuilder<usermodel>();
var connStr = ConfigurationManager.ConnectionStrings["UserDBConn"].ConnectionString;

var connection = new SqlConnection(connStr);

using (var ctx = builder.Create(connection))
{
    if (ctx.DatabaseExists())
        ctx.DeleteDatabase();
     ctx.CreateDatabase();
</usermodel></pre>

My project and auto generated tables ended up looking like this:
<a href="http://jasonrowe.com/wp-content/uploads/2009/12/sql_result1.png"><img src="http://jasonrowe.com/wp-content/uploads/2009/12/sql_result1.png" alt="sql results from code only" title="sql_result" width="211" height="309" class="alignnone size-full wp-image-848" /></a>


<a href="http://jasonrowe.com/2009/12/11/entity-framework-code-only/efprojectsetup/" rel="attachment wp-att-784"><img src="http://jasonrowe.com/wp-content/uploads/2009/12/EFProjectSetup-262x300.PNG" alt="EFProjectSetup" title="EFProjectSetup" width="262" height="300" class="alignnone size-medium wp-image-784" /></a>

So after going through this quick setup I got a taste of what is to come.  I&#8217;m still going to stick with ActiveRecord for my ORM but I think EF will definitly be an option in the future.  Also, the code only mode will be a little more comfortable for people who have an ActiveRecord background. 


Entity Framework blog posts
<ol>
	<li><a href="http://blogs.msdn.com/efdesign/archive/2009/06/10/code-only.aspx">Code Only Announcement</a></li>

	<li><a href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-code-only-for-entity-framework.aspx">Code Only Walk Through Entity FrameWork</a></li>

	<li><a href="http://blogs.msdn.com/efdesign/archive/2009/08/03/code-only-enhancements.aspx">Code Only Enhancements</a></li>

	<li><a href="http://blogs.msdn.com/efdesign/archive/2009/10/12/code-only-further-enhancements.aspx">Even More Code Only Enhancements!</a></li>
</ol></profile>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/12/11/entity-framework-code-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

