<?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>EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx</link><description>The information in this post is out of date. Visit msdn.com/data/ef for the latest information on current and past releases of EF. Validation is a new feature introduced in Entity Framework Feature Community Technology Preview 5 (CTP5) which enables to</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10219353</link><pubDate>Mon, 03 Oct 2011 20:53:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10219353</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;It seems ValidateEntity is not called within the same database transaction. Therefore, there may be race conditions with other entities in the database.&lt;/p&gt;
&lt;p&gt;For instance, with a unique property validator.&lt;/p&gt;
&lt;p&gt;protected override DbEntityValidationResult ValidateEntity(DbEntityEntry entityEntry, IDictionary&amp;lt;object, object&amp;gt; items) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; var validation_state = base.ValidateEntity(entityEntry, items);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; if (entityEntry.Entity is User) {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var entity = (User)entityEntry.Entity;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var set = Users;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; //check name unique&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!(set.Any(any_entity =&amp;gt; any_entity.Name == entity.Name))) {} else {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; validation_state.ValidationErrors.Add(new DbValidationError(&amp;quot;Name&amp;quot;, &amp;quot;The Name field must be unique.&amp;quot;));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; return validation_state;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10219353" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10209932</link><pubDate>Tue, 13 Sep 2011 14:52:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10209932</guid><dc:creator>Dave</dc:creator><description>&lt;p&gt;Why don&amp;#39;t you add these attributes for us when doing database first? OR at least have an option to do so. I don&amp;#39;t want to modify the generated code constantly, and perhaps get it wrong if the db changes.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10209932" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10187979</link><pubDate>Tue, 19 Jul 2011 19:14:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10187979</guid><dc:creator>Pawel</dc:creator><description>&lt;p&gt;@James: There is a way to pass your own objects to custom validation and this is the way to pass your context. You do it by overriding DbContext.ValidateEntity method and invoking the method from the base class with non-null dictionarry of custom objects. Take a look at this post: &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/b/adonet/archive/2011/05/27/ef-4-1-validation.aspx"&gt;blogs.msdn.com/.../ef-4-1-validation.aspx&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;There is a section called &amp;quot;Custom Validation Sample: Uniqueness&amp;quot; that does exactly that. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10187979" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10187517</link><pubDate>Mon, 18 Jul 2011 15:20:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10187517</guid><dc:creator>James</dc:creator><description>&lt;p&gt;Is there anyway to get hold of the current context whilst using a custom validation attribute. &amp;nbsp;I am trying to doa unique validation attribute, but cannot see how I get the current context. &amp;nbsp;Unfortunately it is no good creating a new context as this will not contain the &amp;#39;local&amp;#39; list of items pending insert - which also need to be validated against.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10187517" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10182742</link><pubDate>Sun, 03 Jul 2011 19:54:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10182742</guid><dc:creator>Martin F</dc:creator><description>&lt;p&gt;Are you seriously suggesting that people should now start validating user input in the database model ?&lt;/p&gt;
&lt;p&gt;I think it is fine validating before saving to the database as an extra layer of protection securing that database rules are upheld, but these errors should _NEVER_ be reported to the user, it should be logged and the developer should be notified. At best this should be something which is caught when running your tests.&lt;/p&gt;
&lt;p&gt;User input validation should happen before it reaches the database, for example in a view model.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10182742" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10144899</link><pubDate>Wed, 23 Mar 2011 16:46:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10144899</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;I really, really hope this feature will be extended for Model First and Database First. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10144899" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10113203</link><pubDate>Sat, 08 Jan 2011 00:16:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10113203</guid><dc:creator>Derek</dc:creator><description>&lt;p&gt;I&amp;#39;ve been trying CTP5 out and everything I&amp;#39;ve done works great locally. &amp;nbsp;When connecting to a remote database though, I had to specify the connectionString in the constructor for the DbContext as I couldn&amp;#39;t get it to work using the connectionString name.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10113203" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10111594</link><pubDate>Tue, 04 Jan 2011 18:50:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111594</guid><dc:creator>Pawel</dc:creator><description>&lt;p&gt;@tmsmith: I answered your question on the forum. Here is the link: &lt;a rel="nofollow" target="_new" href="http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/2108079c-8160-460e-b703-1800bd910679"&gt;social.msdn.microsoft.com/.../2108079c-8160-460e-b703-1800bd910679&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111594" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10108319</link><pubDate>Wed, 22 Dec 2010 20:55:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10108319</guid><dc:creator>Ludwig</dc:creator><description>&lt;p&gt;@Rik: I have implemented a DDD architecture with EF 4 CTP 5 as the repository implementation in the infrastructure layer. De domain layer is completely independent, has its own tracking and validation mechanism. In my case, because I also own the client, the domain model itself is exposed in the service layer and as such, I can just reuse the domain model on the WPF client, where it is encapsulated by the view models (using MVVM). It also means I reuse every domain logic on back-end and client. Of course, in enterprise applications you would typically not expose the domain model, but instead create specific data contracts, according to the needs of the clients. So in this architecture, EF is only known in the infrastructure layer, where it belongs. Concerning EF: good practise is to have a context per unit of work, but unfortunately EF cannot deal with this very well; so I spent a number of weeks trying to find out a way to make this work, and eventually succeeded (basically I replay the changed recorded by the domain model), but there&amp;#39;s room for improvement in this area - and when EF would actually work well in a disconnected scenario one day, I just need to adapt the repository implementation. (If you want to discuss this further, we could always exchange mail or something.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10108319" width="1" height="1"&gt;</description></item><item><title>re: EF Feature CTP5: Validation</title><link>http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx#10108067</link><pubDate>Wed, 22 Dec 2010 10:56:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10108067</guid><dc:creator>Rik</dc:creator><description>&lt;p&gt;@Ludwig we are having similar problems with EF and would be interested to hear what you would propose as an alternative until EF&amp;#39;s design become more usable.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10108067" width="1" height="1"&gt;</description></item></channel></rss>