﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Aaron D. commented on Playing with Entity Framework Code Only</title><description>The only thing I found that will stop the automatic DDL generation is to create your own do-nothing initializer like so:
  
  
public class DoNothingInitializer : IDatabaseInitializer
&lt;database  
{
  
	public void InitializeDatabase(Database context) { }
  
}
  
  
Where the 
&lt;database generic param is your DbContext class.
  
  
You need to set this as the initializer before any code runs in your DB. I put it in my DbContext's static constructor:
  
  
static Database()
  
{
  
	System.Data.Entity.Infrastructure.Database.SetInitializer(new DoNothingInitializer());
  
}
  
  
I agree that automatically creating the DDL is bad. What's worse is you have to do this or something similar to stop it, but other than that I'm liking where this is going.
&gt;</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment19</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment19</guid><pubDate>Wed, 18 Aug 2010 19:07:52 GMT</pubDate></item><item><title>Pure Krome commented on Playing with Entity Framework Code Only</title><description>@ |)amien - cheers! (and hmm... i always thought u were on the EF team after L2S .. doh. your move slipped under my radar. What you doing on the XBox team?)
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment18</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment18</guid><pubDate>Fri, 13 Aug 2010 02:56:49 GMT</pubDate></item><item><title>Ayende Rahien commented on Playing with Entity Framework Code Only</title><description>Daniel,
  
No schema is different than creating a schema on the fly.
  
More over, my concern is that it only work the first time, the next time, you are going to get an error.
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment17</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment17</guid><pubDate>Thu, 12 Aug 2010 18:36:47 GMT</pubDate></item><item><title>Daniel Pratt commented on Playing with Entity Framework Code Only</title><description>Considering that you seem to have an appreciation for document databases, I am somewhat surprised that you are unhappy with the schema being generated for you automatically.
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment16</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment16</guid><pubDate>Thu, 12 Aug 2010 17:34:43 GMT</pubDate></item><item><title>Bil Simser commented on Playing with Entity Framework Code Only</title><description>Thanks for the quick recap. I've been looking at EF recently as I think it's reaching a maturity state. 
  
  
My biggest beef with the "code first" was partially my misunderstanding of how EF interpreted code first but it centers around automatically generating the schema. When I did a spike the first thing it did was create the db. This is not how I like to develop as I want to run my code/tests a few million times before I'm ready to embark on persistence. Like you, I want DDL to be implicit not some "magic happens here". Maybe the comment Charles left will omit this but I find this cryptic at best and I will forget it. I also want control over the DDL. Maybe the initial creation is spot-on but maybe not. At least with NH I can tweak it and supplement the creation. I'm not seeing that with EF so it seems that other than a database name, there's not a whole lot of options to optimize/tweak the schema creation (or completely bypass it?).
  
  
In any case, I'm still working in prod with NH and FluentNH. It's just proven itself time and time again and never got in my way. EF is in the lab and dev boxes as we try things out. Maybe someday...
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment15</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment15</guid><pubDate>Thu, 12 Aug 2010 13:23:10 GMT</pubDate></item><item><title>Tuna Toksoz commented on Playing with Entity Framework Code Only</title><description>@Damien
  
  
It is like FluentNH+NH Mapping Annotations then. EF Code First is like a both of those in same assembly.
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment14</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment14</guid><pubDate>Thu, 12 Aug 2010 05:30:42 GMT</pubDate></item><item><title>Damien Guard commented on Playing with Entity Framework Code Only</title><description>@Pure Krome: I'm not sure what the long-term plan is there, I'm not on the EF team any more as I moved to Xbox.
  
  
@Nnc: It's not really FluentEF as Code First doesn't have to use the Fluent API. You can use Data Annotations.
  
  
[)amien
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment13</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment13</guid><pubDate>Thu, 12 Aug 2010 04:25:57 GMT</pubDate></item><item><title>Nnc commented on Playing with Entity Framework Code Only</title><description>So we have:
  
  
NHibernate
  
FluentNHibernate
  
  
EntityFramework
  
FluentEntityFramework
  
  
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment12</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment12</guid><pubDate>Thu, 12 Aug 2010 03:22:44 GMT</pubDate></item><item><title>Pure Krome commented on Playing with Entity Framework Code Only</title><description>I've only read those two (referenced) posts u mentioned at the start of the article, Oren .. and I thought that ObjectContext was getting deprecated by the DbContext ... ??
  
  
|)amien? is that true or have a totally misread it? Or is DbContext a new wrapper over ObjectContext?
  
  
(or i still have it completely wrong for the 10secs i read those articles).
  
  
-PK-
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment11</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment11</guid><pubDate>Thu, 12 Aug 2010 00:51:08 GMT</pubDate></item><item><title>Barry Dahlberg commented on Playing with Entity Framework Code Only</title><description>"That is a problem, DDL should never run as an implicit step."
  
  
Having it run automatically in development is quite handy as it keeps the DB up to date with my domain.  They mention somewhere including data in a set up step as well.  The worry is that it could trigger accidently in production which is scary.  I think I'd prefer it off by default but easy to turn on.
  
  
What I would really like to see is a bigger story around database migrations along the lines of Rails etc.  What are yout thoughts on that style of working?
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment10</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment10</guid><pubDate>Wed, 11 Aug 2010 19:45:12 GMT</pubDate></item><item><title>Imran commented on Playing with Entity Framework Code Only</title><description>Not looked at EF for  a while, but i wonder if it still has problems with generating horribly inefficient sql.
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment9</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment9</guid><pubDate>Wed, 11 Aug 2010 18:21:23 GMT</pubDate></item><item><title>Charles Vallance commented on Playing with Entity Framework Code Only</title><description>Hey Ayende, I too have been playing around with the code first stuff and find it refreshing. And I think I can help you out with a couple of points...
  
  
To stop the database creation, I think you do this:
  
  
	public ToDoContext():base(model)
  
	{
  
	    Database.SetInitializer&lt;ToDoContext&gt;(null);
  
	}
  
  
And to get rid of that metadata table (which is used internally to work out if the schema matches the model), you can do this:
  
  
	static ToDoContext()
  
	{
  
	    var modelBuilder = new ModelBuilder();
  
  
	    modelBuilder.IncludeMetadataInDatabase = false;
  
  
	    modelBuilder.DiscoverEntitiesFromContext(typeof(ToDoContext));
  
	    modelBuilder.Entity
&lt;user	().HasKey(x =&gt; x.Username);
  
	    model = modelBuilder.CreateModel();
  
	}
&gt;  
  
Charles
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment8</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment8</guid><pubDate>Wed, 11 Aug 2010 16:20:59 GMT</pubDate></item><item><title>Damien Guard commented on Playing with Entity Framework Code Only</title><description>Glad you are enjoying it so far. 
  
  
IsRequired is only exposed on members you are mapping. HasRequired is used to declare relationships (the WithX is quite cool, especially when you start doing required to required and the With method names now slightly change so you can declare which is the principal end to allow cascade on delete etc to work).
  
  
While you could argue that having two 'Required' methods are confusing they actually operate in very similar ways. i.e. define whether the underlying column supports nullability.
  
  
The Has prefix could theoretically get dropped but some chains look ugly, e.g.
  
  
Entity
&lt;customer().many(x&gt;
 x.Address).Required(a =&gt; a.Customer);
  
  
[)amien
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment7</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment7</guid><pubDate>Wed, 11 Aug 2010 15:06:14 GMT</pubDate></item><item><title>Alex Simkin commented on Playing with Entity Framework Code Only</title><description>This is nothing. Wait until Microsoft.Data reaches RTW - it will blow your head away.
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment6</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment6</guid><pubDate>Wed, 11 Aug 2010 12:49:40 GMT</pubDate></item><item><title>Ayende Rahien commented on Playing with Entity Framework Code Only</title><description>Felipe,
  
No, EF doesn't have something similar to NH Futures
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment5</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment5</guid><pubDate>Wed, 11 Aug 2010 12:08:37 GMT</pubDate></item><item><title>Ayende Rahien commented on Playing with Entity Framework Code Only</title><description>Andrey,
  
I am probably not the best guy to ask
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment4</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment4</guid><pubDate>Wed, 11 Aug 2010 12:07:56 GMT</pubDate></item><item><title>Felipe Fujiy commented on Playing with Entity Framework Code Only</title><description>Ayende, you put selects together or EF send it as batch? This is strange since you call ToList()
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment3</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment3</guid><pubDate>Wed, 11 Aug 2010 10:47:33 GMT</pubDate></item><item><title>Steve W commented on Playing with Entity Framework Code Only</title><description>I too was quite struck with the initial similarity to the Fluent NHibernate API, and I'm generally quite impressed with how the product works at the moment given that this is an early preview. That said, there are a few things that stand out as missing - e.g. I couldn't find a good way to map collections without having a generic ICollection exposed as a public property on the entity class (I only spent a few minutes looking though, I may have missed something). Presumably, more features will be added with future releases.
  
  
Generally, I'm sort of vaguely hopeful that this will become a solid approach to code first / code only database development in the near future - fingers crossed...
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment2</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment2</guid><pubDate>Wed, 11 Aug 2010 10:42:43 GMT</pubDate></item><item><title>Andrey Shchekin commented on Playing with Entity Framework Code Only</title><description>Is it possible not to map the Id?
</description><link>http://ayende.com/4583/playing-with-entity-framework-code-only#comment1</link><guid>http://ayende.com/4583/playing-with-entity-framework-code-only#comment1</guid><pubDate>Wed, 11 Aug 2010 10:28:32 GMT</pubDate></item></channel></rss>