<?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>.Net and MOSS News</title>
	<atom:link href="http://nadege.deroussen.net/feed" rel="self" type="application/rss+xml" />
	<link>http://nadege.deroussen.net</link>
	<description>.Net and Sharepoint informations, tips and tricks</description>
	<lastBuildDate>Tue, 21 Feb 2012 12:34:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>EF Code First : Add foreign key relationship</title>
		<link>http://nadege.deroussen.net/ef-code-first-add-foreign-key-relationship</link>
		<comments>http://nadege.deroussen.net/ef-code-first-add-foreign-key-relationship#comments</comments>
		<pubDate>Mon, 23 Jan 2012 19:31:15 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[EF]]></category>
		<category><![CDATA[EF CodeFirst]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Sample]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1126</guid>
		<description><![CDATA[In the first article, I show how to create a database with one table using Code First. You can read it here : EF Code First : Simple sample Now, we want to add a new table to work with foreign key. Let&#8217;s add a new Project class like this : public class Project { [...]]]></description>
			<content:encoded><![CDATA[<p>In the first article, I show how to create a database with one table using Code First. You can read it here : <a href="http://nadege.deroussen.net/ef-code-first-simple-sample">EF Code First : Simple sample</a></p>
<p>Now, we want to add a new table to work with foreign key. Let&#8217;s add a new Project class like this :</p>
<pre class="brush:csharp">public class Project
{
    public int ProjectId { get; set; }
    public string Name { get; set; }
    public int ManagerId { get; set; }
    public Person Manager { get; set; }
}</pre>
<p>You can see the Manager property is of type Person and I add ManagerId property to be the key between the two tables.</p>
<p>Now add the DbSet of Project as you&#8217;ve done for Person :</p>
<pre class="brush:csharp">public DbSet Projects { get; set; }</pre>
<p>And run the application.<br />
<span id="more-1126"></span></p>
<p>You should get an InvalidOperationException :<br />
<em>The model backing the &#8216;MyContext&#8217; context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.</em></p>
<p>This is because the changes we made have too more effect on the database and it should be deleted. But the EF Context can&#8217;t decide itself if it can drop the database to recreate it.<br />
What&#8217;s the solution ?<br />
There is two solutions :</p>
<ul>
<li>You can delete the database yourself and rerun the application</li>
<li>You can use the SetInitializer using DropCreateDatabaseIfModelChanges.</li>
</ul>
<p>I won&#8217;t explain the first solution. About the second one, it&#8217;s a feature allowed by Code First. You can ask the context to automatically drop and recreate the database if the model change.<br />
You should be very careful with this option, because in a production environment, you can loose all your datas.</p>
<p>Because we don&#8217;t want to drop ourself the database, we will see how to tell the context to do it for us.</p>
<p>In the file MyContext.cs, add a new class : MyInitializer</p>
<pre class="brush:csharp">public class MyInitializer : DropCreateDatabaseIfModelChanges
{
}</pre>
<p>As you can see, the database would be dropped and recreated each time the model change.<br />
You can do more things in the initializer but we will see that later in this post.</p>
<p>Now we will set the initializer. Go back to Program.cs and add the following line at the beginning of the Main method :</p>
<pre class="brush:csharp">Database.SetInitializer(new MyInitializer());</pre>
<p>Now, you can run our application.</p>
<p>What has hapenned ? The context has detected changes in the model and so, the database has been deleted and recreated. If you check the tables in the database, you should see 2 tables : <em>People</em> and <em>Project</em>.<br />
The person in the Main method has been created in the People table. The item appears only once because the table was recreated and so, the previous record was deleted and not backed up.</p>
<p>If we look closer, we can see a column named ManagerId and another one named Manager_PersonId.<br />
<div id="attachment_1144" class="wp-caption aligncenter" style="width: 310px"><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/ProjectTable1.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/ProjectTable1-300x110.png" alt="" title="Project table with FK auto generated" width="300" height="110" class="size-medium wp-image-1144" /></a><p class="wp-caption-text">Project table with FK auto generated</p></div><br />
The first one was created because of our property <em>ManagerId</em>. The second one was created because of our navigation property to the list of <em>Person</em>. </p>
<p><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/ProjectManager-relationship.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/ProjectManager-relationship-300x105.png" alt="" title="Project Manager relationship" width="300" height="105" class="aligncenter size-medium wp-image-1143" /></a></p>
<p>EF Code First has created a foreign key for us and it&#8217;s great, but what we&#8217;d want is to use the ManagerId property.<br />
So let&#8217;s modify our Project class to use this property whereas let Code First create it for us.</p>
<p>To configure Code First and the way it will generate our database, there is two methods : <strong>DataAnnotation</strong> and <strong>Fluent API</strong></p>
<p>Let&#8217;s use DataAnnotation.<br />
Modify your class like this :</p>
<pre class="brush:csharp">public class Project
{
    public int ProjectId { get; set; }
    public string Name { get; set; }
    public int ManagerId { get; set; }
    [ForeignKey("ManagerId")]
    public Person Manager { get; set; }
}</pre>
<p>You should add the <strong>System.ComponentModel.DataAnnotations</strong> namespace.<br />
Adding the ForeignKey attribute, we say to Code First that we want the ManagerId properties to be used as Foreign Key to the Person table.</p>
<p>Run the application and check your database schema. The <em>Manager_PersonId</em> column does not exist anymore, there is only the ManagerId column and it is declare as a foreign key to the People table.</p>
<p><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/Project-columns-with-FK.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/Project-columns-with-FK.png" alt="" title="Project columns with FK" width="158" height="132" class="aligncenter size-full wp-image-1142" /></a></p>
<p>We just create our first one to many relationship using EF Code First. As we have seen, we can declare the FK in the class or let Code First managed it for us.<br />
In the next article, we will talk about Data Annotation and Code Fluent.</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/ef-code-first-add-foreign-key-relationship/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Series of articles about EF Code First</title>
		<link>http://nadege.deroussen.net/series-of-articles-about-ef-code-first</link>
		<comments>http://nadege.deroussen.net/series-of-articles-about-ef-code-first#comments</comments>
		<pubDate>Thu, 19 Jan 2012 19:13:31 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[EF]]></category>
		<category><![CDATA[Code Fluent]]></category>
		<category><![CDATA[Data Annotations]]></category>
		<category><![CDATA[EF CodeFirst]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Sample]]></category>
		<category><![CDATA[TPH]]></category>
		<category><![CDATA[TPT]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1121</guid>
		<description><![CDATA[As I begin to work a lot with Entity Framework Code First, I decide to write some articles to share some samples that could be useful for beginners. Here is how I think to organize it : 1 &#8211; First sample : A very simple example on how to create a database with a table [...]]]></description>
			<content:encoded><![CDATA[<p>As I begin to work a lot with Entity Framework Code First, I decide to write some articles to share some samples that could be useful for beginners.<br />
Here is how I think to organize it :</p>
<p>1 &#8211; <a href="http://nadege.deroussen.net/ef-code-first-simple-sample">First sample</a> : A very simple example on how to create a database with a table<br />
2 &#8211; <a href="http://nadege.deroussen.net/?p=1126">Add foreign key relationship</a> : We will enhanced the application created on the first tutorial to add relationships.<br />
3 &#8211; Data Annotation and Code Fluent configuration<br />
4 &#8211; Initialize database with data<br />
5 &#8211; Table per Type and Table per Hierarchy</p>
<p>I hope I&#8217;ll find enough time to write all of this.<br />
Hopefully, I already write the first one !</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/series-of-articles-about-ef-code-first/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>EF Code First : Simple sample</title>
		<link>http://nadege.deroussen.net/ef-code-first-simple-sample</link>
		<comments>http://nadege.deroussen.net/ef-code-first-simple-sample#comments</comments>
		<pubDate>Tue, 17 Jan 2012 21:41:08 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[EF CodeFirst]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Sample]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1094</guid>
		<description><![CDATA[You heard about Entity Framework and want to try it. Let&#8217;s start with a very simple example. We will create a Console Application, add a class Person and generate the database from this class. Open Visual Studio and create a Console Application. I called mine EFFirstSample. Now, you have to allow Code First on your [...]]]></description>
			<content:encoded><![CDATA[<p>You heard about Entity Framework and want to try it. Let&#8217;s start with a very simple example. We will create a Console Application, add a class Person and generate the database from this class.<br />
Open Visual Studio and create a Console Application. I called mine <strong>EFFirstSample</strong>.<br />
Now, you have to allow Code First on your project. To do that, add Entity Framework from NuGet package. Open Visual Studio, go to <strong>Tools -&gt; Library Package Manager -&gt; Manage NuGet Packages</strong> and select <strong>EntityFramework</strong>package. It will add all references to your project.</p>
<div id="attachment_1097" class="wp-caption aligncenter" style="width: 310px"><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/EF.CF-AddPackage.png"><img class="size-medium wp-image-1097" title="EF.CF-AddPackage" src="http://nadege.deroussen.net/wp-content/uploads/2012/01/EF.CF-AddPackage-300x148.png" alt="Add package" width="300" height="148" /></a><p class="wp-caption-text">Add package</p></div>
<p>Once added, check references in your project. <strong>EntityFramework</strong> should have appeared. You should also see a new file package.config. This file contains all information about NuGet packages installed.<br />
<span id="more-1094"></span></p>
<p>Ok, so now, we can start our project. We will first add a new class file : Person.cs and declare four properties : an ID, a lastname, a firstname and a date of birth, like this :</p>
<pre class="brush:csharp">public class Person
{
    public int PersonId { get; set; }
    public string LastName { get; set; }
    public string FirstName { get; set; }
    public DateTime BirthDate { get; set; }
}</pre>
</p>
<p>Now, we will create a class to manage the link with the database : our DBContext. Add a new class MyContext.cs and let it inherite from <strong>DbContext</strong> class (add <strong>System.Data.Entity</strong> as using)</p>
<pre class="brush:csharp">using System.Data.Entity;

namespace EFFirstSample
{
    public class MyContext : DbContext
    {
        public MyContext()
        {}
    }
}</pre>
<p>So now, we will tell to the context what should be created in the database. Add the following line :</p>
<pre class="brush:csharp">public DbSet&lt;Person&gt; Persons { get; set; }</pre>
<p>It allow the context to know that it will contains a collection of Persons (and that a table Person should be created).<br />
If we run the application, nothing will happen. You can check, connecting to your SqlExpress instance.<br />
Let&#8217;s add some code in our Console, to call our context. Go to Program class and modify it like that :</p>
<pre class="brush:csharp">static void Main(string[] args)
{
    var person = new Person {FirstName = "Nadege", LastName = "Deroussen", BirthDate = DateTime.Now};
    using (var context = new MyContext())
    {
        context.Persons.Add(person);
        context.SaveChanges();
    }
    Console.Write("Person saved !");
    Console.ReadLine();
}</pre>
<p>We just create a new Person and add it to the database. Now, run the application and check the message before closing.<br />
<div id="attachment_1103" class="wp-caption aligncenter" style="width: 310px"><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/EF.CF-FirstLaunch.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/EF.CF-FirstLaunch-300x40.png" alt="First launch of the application" title="EF.CF-FirstLaunch" width="300" height="40" class="size-medium wp-image-1103" /></a><p class="wp-caption-text">Save a person</p></div></p>
<p>It&#8217;s time to check in the person was well created. Connect to SqlExpress and check that a new database was created.</p>
<p>On the Toolbar <em>Server Explorer</em>, you should be a Data Connections node. If the toolbar is not visible, go to <em>View -> Server Explorer</em></p>
<p><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/EF.CF-DataConnection.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/EF.CF-DataConnection.png" alt="Data Connection node in Server Explorer toolbar" title="EF.CF-DataConnection" width="207" height="152" class="aligncenter size-full wp-image-1165" /></a></p>
<p>Right click on the node and select <em>Add connection</em>. A new window appears. Add your server (.\SqlExpress if you use SQL Express) and select your database in the dropdownlist. Here is what I have :</p>
<p><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/EF.CF-AddConnection.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/EF.CF-AddConnection-204x300.png" alt="Add Data Connection" title="EF.CF-AddConnection" width="204" height="300" class="aligncenter size-medium wp-image-1166" /></a></p>
<p>Test your connection and validate with the OK button. You should now see your database.</p>
<p><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/WhereIsPersonTable.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/WhereIsPersonTable-300x217.png" alt="Screen capture of server explorer showing a table People" title="DatabaseCreated" width="300" height="217" class="aligncenter size-medium wp-image-1109" /></a></p>
<p>You can see a People table and an EdmMetadata table. The first one represent the table corresponding to your Person class. Why is it name People ? Because of naming convention. EF Code First uses pluralization rules and so our DbSet Persons is rename &#8220;People&#8221;, singularized.<br />
Right click on the table name and select <strong>Open table definition</strong>. You should see something like that :</p>
<p><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/PersonTableDefinition.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/PersonTableDefinition-300x298.png" alt="" title="Person Table Definition" width="300" height="298" class="aligncenter size-medium wp-image-1130" /></a></p>
<p>You can see the PersonId has been created as a primary key. How is it possible ? We don&#8217;t specify anything !<br />
It&#8217;s simple. Code First uses naming convention to determine which property should be used as primary key. If you name a property <em>TableName</em>Id, Code First will see that this property will be used to define the primary key. Very simple.<br />
There is other way to define the property that would match the primary key. We will see that in a future post.</p>
<p>The other table, EdmMetadata, stores a hash that will allow EF to check if there is modification to the model or not.</p>
<p>You just create your first, simple, application with Entity Framework Code First.<br />
In a future post, we will see how to add multiple table with foreign key.</p>
<p><strong>Edit (Jan, 27th 2012)</strong> : Add  information on how to connect to the database</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/ef-code-first-simple-sample/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[EF Code First] What happen to my Person table ?</title>
		<link>http://nadege.deroussen.net/ef-code-first-what-happen-to-my-person-table</link>
		<comments>http://nadege.deroussen.net/ef-code-first-what-happen-to-my-person-table#comments</comments>
		<pubDate>Tue, 17 Jan 2012 20:49:03 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[EF CodeFirst]]></category>
		<category><![CDATA[Pluralization]]></category>
		<category><![CDATA[Rules]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1108</guid>
		<description><![CDATA[I&#8217;m writing an article about EF Code Fisrt and i get a strange behaviour. I create a simple class Person : public class Person { public int PersonId { get; set; } public string LastName { get; set; } public string FirstName { get; set; } public DateTime BirthDate { get; set; } } I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing an article about EF Code Fisrt and i get a strange behaviour. I create a simple class Person :</p>
<pre class="brush:csharp">
public class Person
{
    public int PersonId { get; set; }
    public string LastName { get; set; }
    public string FirstName { get; set; }
    public DateTime BirthDate { get; set; }
}
</pre>
<p>I create my context with a DbSet of Person :</p>
<pre class="brush:csharp">public class MyContext : DbContext
{
   public DbSet&lt;Person&gt; Persons { get; set; }

    public MyContext()
    {}
}</pre>
<p>Nothing special. I create a new Person in a console application and add it to the context, so the table Person is created and the new row added :</p>
<pre class="brush:csharp">static void Main(string[] args)
{
    var person = new Person {FirstName = "Nadege", LastName = "Deroussen", BirthDate = DateTime.Now};
    using (var context = new MyContext())
    {
        context.Persons.Add(person);
    }
    Console.Write("Person saved !");
    Console.ReadLine();
}</pre>
<p>I run the application and connect to my SqlExpress to check the database was created and this is what I obtain :<br />
<div id="attachment_1109" class="wp-caption aligncenter" style="width: 310px"><a href="http://nadege.deroussen.net/wp-content/uploads/2012/01/WhereIsPersonTable.png"><img src="http://nadege.deroussen.net/wp-content/uploads/2012/01/WhereIsPersonTable-300x217.png" alt="Screen capture of server explorer showing a table People" title="WhereIsPersonTable" width="300" height="217" class="size-medium wp-image-1109" /></a><p class="wp-caption-text">Where is the Person table ?</p></div></p>
<p>I get a People table. I return to Visual Studio to check I don&#8217;t make a mistake and I run a search on the entire solution. No occurence of &#8220;People&#8221;.<br />
Where is my Person table ? Why do I get a People table ?<br />
For information, I use Entity Framework 4.2. </p>
<p><strong>Does somebody know how to explain that ?</strong></p>
<p><strong>Edit 19/01/2012</strong> :<br />
Ok, I get the answer from Diego Vega. It&#8217;s just because of pluralization rules. As my DbSet is named Persons, Code First, creating the table, singularize the name and Person become People and no Person as I was expecting.</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/ef-code-first-what-happen-to-my-person-table/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework Code First by Julie Lerman and Rowan Miller</title>
		<link>http://nadege.deroussen.net/entity-framework-code-first-by-julie-lerman-and-rowan-miller</link>
		<comments>http://nadege.deroussen.net/entity-framework-code-first-by-julie-lerman-and-rowan-miller#comments</comments>
		<pubDate>Tue, 06 Dec 2011 06:40:25 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[EF]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[EF CodeFirst]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1086</guid>
		<description><![CDATA[If you are looking for a great book to learn more about EF Code First, how it works and how to tune it, here is a really good book : Entity Framework Code First by Julie Lerman and Rowan Miller I just finished it and I learned lots of things about configuring inheritance, mapping, caching [...]]]></description>
			<content:encoded><![CDATA[<p>If you are looking for a great book to learn more about EF Code First, how it works and how to tune it, here is a really good book : <a href="http://www.amazon.fr/Programming-Entity-Framework-First-ebook/dp/B006C3CXTA/ref=sr_1_2?ie=UTF8&amp;qid=1323157266&amp;sr=8-2">Entity Framework Code First by Julie Lerman and Rowan Miller</a><br />
I just finished it and I learned lots of things about configuring inheritance, mapping, caching and so much&#8230;</p>
<div id="attachment_1087" class="wp-caption aligncenter" style="width: 160px"><a href="http://nadege.deroussen.net/wp-content/uploads/2011/12/EF-Code-First.jpg"><img class="size-thumbnail wp-image-1087" title="EF Code First" src="http://nadege.deroussen.net/wp-content/uploads/2011/12/EF-Code-First-150x150.jpg" alt="EF Code First, book cover" width="150" height="150" /></a><p class="wp-caption-text">Entity Framework : Code First</p></div>
<p>You can find the book as paperback or Kindle edition.</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/entity-framework-code-first-by-julie-lerman-and-rowan-miller/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPMetal and Publishing Field in Sharepoint</title>
		<link>http://nadege.deroussen.net/spmetal-and-publishing-field-in-sharepoint</link>
		<comments>http://nadege.deroussen.net/spmetal-and-publishing-field-in-sharepoint#comments</comments>
		<pubDate>Tue, 04 Oct 2011 11:51:55 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[SP2010]]></category>
		<category><![CDATA[Publishing]]></category>
		<category><![CDATA[SPMetal]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1064</guid>
		<description><![CDATA[For a reason I don&#8217;t know, when you try to generate entity classes for your sharepoint site, SPMetal doesn&#8217;t generate property for Publishing field. Imagine a field declare like that : &#60;Field ID="{B126F0CB-C1C3-476E-A499-80528707A784}" Name="Comments" DisplayName="Comments" Type="HTML" RichText="TRUE" RichTextMode="FullHtml" Required="TRUE" /&#62; Here is a solution to this problem. Create a partial class for accessing your list [...]]]></description>
			<content:encoded><![CDATA[<p>For a reason I don&#8217;t know, when you try to generate entity classes for your sharepoint site, SPMetal doesn&#8217;t generate property for Publishing field.</p>
<p>Imagine a field declare like that :</p>
<pre class="brush:xml">&lt;Field ID="{B126F0CB-C1C3-476E-A499-80528707A784}" Name="Comments" DisplayName="Comments" Type="HTML" RichText="TRUE" RichTextMode="FullHtml" Required="TRUE" /&gt;</pre>
<p>Here is a solution to this problem. Create a partial class for accessing your list and add manually a property like this :</p>
<pre class="brush:csharp">public partial class MyClassCT
    {
        private string _comments;

        [Microsoft.SharePoint.Linq.ColumnAttribute(Name = "Comments", Storage = "_comments", FieldType = "Text")]
        public string Comments
        {
            get { return _comments; }
            set
            {
                if ((value != this._comments))
                {
                    this.OnPropertyChanging("Comments", this._comments);
                    this._comments= value;
                    this.OnPropertyChanged("Comments");
                }
            }
        }
    }</pre>
<p>As you can see, I declare the fieldtype as <strong>Text</strong> and so, the property can be a simple string.<br />
That&#8217;s it, you can now access the property like any others.</p>
<p>This works very well for reading, but when you try to create or update the list, you would get this error :<br />
<em>Incompatible column types. Previous type: Text . Current type: Invalid.</em></p>
<p>After some research, I can&#8217;t find which type should be use. I try <strong>FieldType = &#8220;Invalid&#8221;</strong> and &#8230;, it works.<br />
Here is the column attribute definition :</p>
<pre class="brush:xml">[ColumnAttribute(Name = "Comments", Storage = "_comments", FieldType = "Invalid")]</pre>
<p>There is some things I don&#8217;t understand. If someone can explain me why Invalid is considered as a good value, I would be very grateful !</p>
<p>NB : your field must be declare as <strong>HTML</strong> is the schema.xml.</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/spmetal-and-publishing-field-in-sharepoint/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DropDownList from enum in Asp.Net MVC</title>
		<link>http://nadege.deroussen.net/dropdownlist-from-enum-in-asp-net-mvc</link>
		<comments>http://nadege.deroussen.net/dropdownlist-from-enum-in-asp-net-mvc#comments</comments>
		<pubDate>Mon, 19 Sep 2011 17:12:34 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[DropDownList]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1058</guid>
		<description><![CDATA[I found an excellent article that explain how to play with enum in a form. Stuart Leeks explains how to create an extension method to render enumeration as dropdownlist. I&#8217;m not going to re-explain all. Just share the article with you : ASP.NET MVC &#8211; Creating a DropDownList helper for enums Edit (20/09/2011) : If [...]]]></description>
			<content:encoded><![CDATA[<p>I found an excellent article that explain how to play with enum in a form. <a href="http://blogs.msdn.com/b/stuartleeks/" title="Stuart Leeks" target="_blank">Stuart Leeks</a> explains how to create an extension method to render enumeration as dropdownlist.<br />
I&#8217;m not going to re-explain all. Just share the article with you : <a title="ASP.NET MVC - Creating a DropDownList helper for enums" href="http://blogs.msdn.com/b/stuartleeks/archive/2010/05/21/asp-net-mvc-creating-a-dropdownlist-helper-for-enums.aspx" target="_blank">ASP.NET MVC &#8211; Creating a DropDownList helper for enums</a></p>
<p><strong>Edit (20/09/2011) :</strong><br />
If you are interested by the <em>PascalCaseWordSplittingEnumConverter</em>, you can find the code in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/dropdownlist-from-enum-in-asp-net-mvc/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asp.Net MVC, Login and ReturnUrl</title>
		<link>http://nadege.deroussen.net/asp-net-mvc-login-and-returnurl</link>
		<comments>http://nadege.deroussen.net/asp-net-mvc-login-and-returnurl#comments</comments>
		<pubDate>Mon, 19 Sep 2011 16:24:41 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[ActionLink]]></category>
		<category><![CDATA[Authorize]]></category>
		<category><![CDATA[ReturnUrl]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1051</guid>
		<description><![CDATA[If you use AuthorizeAttribute in your controller, you surely encountered this kind of &#8220;issue&#8221;. Imagine, you try to create a blog application and on your Home, you let a &#8220;Add new article&#8221; link. As you want to protect your blog, you add an Authorize attribute on your Create method in the controller like this : [...]]]></description>
			<content:encoded><![CDATA[<p>If you use AuthorizeAttribute in your controller, you surely encountered this kind of &#8220;issue&#8221;. Imagine, you try to create a blog application and on your Home, you let a &#8220;Add new article&#8221; link. As you want to protect your blog, you add an Authorize attribute on your Create method in the controller like this :</p>
<pre class="brush:csharp">[Authorize(Roles = "Contributor, Administrator")]
public ActionResult Create()
{
    return View("Create");
}</pre>
<p>Only Contributors could add articles to your blog. Fine !<br />
Now, run your app and click on the &#8220;Add new article&#8221; link. Wow, you&#8217;re redirected to the login page. It&#8217;s perfect. You don&#8217;t have to manage it yourself. So, let&#8217;s try if it works. Connect with an account with Contributor rights. You are redirected to the Home page. Not so bad, but now, you have to click again on the link. It could be better if you can be redirected to the page you want to go.</p>
<p>It&#8217;s possible. You can modify your ActionLink to specify a returnUrl. It&#8217;s a simple attribute to add, like you can specify an area or a CSS style. Here is how to do :</p>
<pre class="brush:csharp">@Html.ActionLink("Add new article", "Create", "Article", new { returnUrl = HttpContext.Current.Request.RawUrl }, null)</pre>
<p>Now, when you click on the &#8220;Create&#8221; link and log in after being redirected, you are no longer redirected to the Home but to the Create page for articles.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/asp-net-mvc-login-and-returnurl/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[EF] The specified type member &#8216;Property&#8217; is not supported in LINQ to Entities</title>
		<link>http://nadege.deroussen.net/ef-the-specified-type-member-property-is-not-supported-in-linq-to-entities</link>
		<comments>http://nadege.deroussen.net/ef-the-specified-type-member-property-is-not-supported-in-linq-to-entities#comments</comments>
		<pubDate>Wed, 14 Sep 2011 14:17:52 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[EntityFramework]]></category>
		<category><![CDATA[LinqToEntity]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=1046</guid>
		<description><![CDATA[I&#8217;m playing with ASP.Net MVC and Entity Framework and I just encountered this error : &#8220;The specified type member &#8216;Property&#8217; is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.&#8220;. I&#8217;m trying to display a list of posts in my view (yes, it is MVC) and my post [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m playing with ASP.Net MVC and Entity Framework and I just encountered this error : &#8220;<b>The specified type member &#8216;Property&#8217; is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.</b>&#8220;.<br />
I&#8217;m trying to display a list of posts in my view (yes, it is MVC) and my post object has an enum property. It seems to be the problem.</p>
<p>Here is my object definition :</p>
<pre class="brush:csharp">public enum PostStatut
    {
        Draft,
        Pending,
        Published,
        Deleted
    }

public class Article
    {
        public int ArticleID { get; set; }

        [Required(ErrorMessage = "Title is required")]
        public string Title { get; set; }

        [Required(ErrorMessage = "Content is required")]
        [AllowHtml]
        public string Content { get; set; }

        [Required(ErrorMessage = "DateCreation is mandatory")]
        [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:dd/MM/yyyy hh:mm}")]
        public DateTime DateCreation { get; set; }

        public virtual IList&lt;Commentaire&gt; Commentaires { get; set; }

        public int? AuthorID { get; set; }
        [ForeignKey("AuthorID")]
        public Person Author { get; set; }

        [Column("Statut", TypeName = "int")]
        public int InternalStatut { get; set; }

        [NotMapped]
        public PostStatut Statut
        {
            get { return (PostStatut)InternalStatut; }
            set { InternalStatut = (int)value; }
        }</pre>
<p>You can see that I have an enum property : <strong>PostStatus</strong> and a property to manage enum with Entity Framework : <strong>InternalStatut</strong>, a simple integer.</p>
<p>In my home page, I try to display all my posts that have a Published status. here is my query :</p>
<pre class="brush:csharp">return _context.Articles.Include("Commentaires").Include("Author").Where(a =&gt; a.Statut == PostStatut.Published).OrderBy(a =&gt; a.DateCreation);</pre>
<p>You can see that I use the enumeration in the query and it seems to be THE problem. I modify my query to use the InternalStatut like this :</p>
<pre class="brush:csharp">return _context.Articles.Include("Commentaires").Include("Author").Where(a => a.InternalStatut == (int)PostStatut.Published).OrderBy(a => a.DateCreation);</pre>
<p>And now it works ! EF doesn&#8217;t support query with enumerations yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/ef-the-specified-type-member-property-is-not-supported-in-linq-to-entities/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[CSS] Display block doesn&#8217;t work with IE9</title>
		<link>http://nadege.deroussen.net/css-display-block-doesnt-work-with-ie9</link>
		<comments>http://nadege.deroussen.net/css-display-block-doesnt-work-with-ie9#comments</comments>
		<pubDate>Thu, 11 Aug 2011 06:11:00 +0000</pubDate>
		<dc:creator>Nadege Deroussen</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[IE9]]></category>

		<guid isPermaLink="false">http://nadege.deroussen.net/?p=908</guid>
		<description><![CDATA[Yesterday, I try to make a simple drop down menu with CSS only. I use a simple list like that : &#60;body&#62; &#60;ul class="navigation"&#62; &#60;li&#62; &#60;a href="#"&#62;Menu 1&#60;/a&#62; &#60;/li&#62; &#60;li&#62; &#60;a href="#"&#62;Menu 2&#60;/a&#62; &#60;/li&#62; &#60;li&#62; &#60;a href="#"&#62;Menu 3&#60;/a&#62; &#60;/li&#62; &#60;li&#62; &#60;a href="#"&#62;Settings&#60;/a&#62; &#60;div id="sub"&#62; &#60;ul&#62; &#60;li&#62; &#60;a href="#"&#62;Display&#60;/a&#62; &#60;/li&#62; &#60;li&#62; &#60;a href="#"&#62;Themes&#60;/a&#62; &#60;/li&#62; &#60;li&#62; &#60;a [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I try to make a simple drop down menu with CSS only.</p>
<p>I use a simple list like that :</p>
<pre class="brush:xml">&lt;body&gt;
	&lt;ul class="navigation"&gt;
		&lt;li&gt;
			&lt;a href="#"&gt;Menu 1&lt;/a&gt;
		&lt;/li&gt;
		&lt;li&gt;
			&lt;a href="#"&gt;Menu 2&lt;/a&gt;
		&lt;/li&gt;
		&lt;li&gt;
			&lt;a href="#"&gt;Menu 3&lt;/a&gt;
		&lt;/li&gt;
		&lt;li&gt;
			&lt;a href="#"&gt;Settings&lt;/a&gt;
			&lt;div id="sub"&gt;
				&lt;ul&gt;
					&lt;li&gt;
						&lt;a href="#"&gt;Display&lt;/a&gt;
					&lt;/li&gt;
					&lt;li&gt;
						&lt;a href="#"&gt;Themes&lt;/a&gt;
					&lt;/li&gt;
					&lt;li&gt;
						&lt;a href="#"&gt;Account&lt;/a&gt;
					&lt;/li&gt;
				&lt;/ul&gt;
			&lt;/div&gt;
		&lt;/li&gt;
	&lt;/ul&gt;
&lt;/body&gt;</pre>
<p>and add this simple css to hide or show my sub menu :</p>
<pre class="brush:xml">&lt;style&gt;
#sub ul {
    display: none;
}
li:hover &gt; #sub ul {
    display: block;
}
&lt;/style&gt;</pre>
<p>I try to display this in Chrome and it works pretty fine. I open it with Firefox and my menu shows well too. I try to open it with IE 9 and here, nothing happen.<br />
When my mouse is over the Settings item, nothing happens. My menu doesn&#8217;t show ? Is it a problem with <code>display:block</code> and IE 9 or is it my css that should be done another way ?<br />
If somebody know how to do it works, just tell me ! I would be very happy.</p>
<p>I also try &#8220;<code>inline</code>&#8221; and &#8220;<code>list-item</code>&#8221; as value for the <code>display</code> attribute but I have the same result : works with Firefox and Chrome but not with IE 9 (I don&#8217;t try to use it with older version of IE 9).</p>
<p><strong>Update :</strong><br />
Thanks to <a title="Batiste Rouelle" href="http://twitter.com/BatisteRouelle" target="_blank">BatisteRouelle</a>, I have my menu works with css only on IE 9.<br />
I have to add a meta asking to render for IE 9 compatibility :</p>
<pre class="brush:xml">&lt;meta http-equiv="X-UA-Compatible" content="IE=9" &gt;</pre>
<p><strong>Update 12/08/2011:</strong> Trying to understand why this happen, we try to add the html page in an IIS Web Site and, using the default DOCTYPE, it works ! The problem is about autorization. IE, and only IE, don&#8217;t allow you to execute some code in local. It&#8217;s a security question. A little disturbing first but a good idea in fact.</p>
]]></content:encoded>
			<wfw:commentRss>http://nadege.deroussen.net/css-display-block-doesnt-work-with-ie9/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

