<?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>Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.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. In this post you’ll see how Code First and the DbContext class in Entity Framework 4.1 RC will work with WCF Data Services</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10249627</link><pubDate>Tue, 20 Dec 2011 16:08:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249627</guid><dc:creator>Chbaeumer</dc:creator><description>&lt;p&gt;Hi Jeff,&lt;/p&gt;
&lt;p&gt;I discovered a serious bug.&lt;/p&gt;
&lt;p&gt;I searched a whole day for &amp;nbsp;the reason why my model didn&amp;#39;t word like your example.&lt;/p&gt;
&lt;p&gt;I always got an exception in function &amp;#39;System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String&amp;amp; keyname, String&amp;amp; keyvalue)&amp;#39; stating that the format is not correct.&lt;/p&gt;
&lt;p&gt;After playing around I discovered that the problem was a database name with spaces in the name. Then the connection string has additional spaces which are not correctly handled by the DbConnectionOptions parser.&lt;/p&gt;
&lt;p&gt;After using a databasename without spaces my example worked like charm.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249627" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10219822</link><pubDate>Tue, 04 Oct 2011 15:19:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10219822</guid><dc:creator>Hayley</dc:creator><description>&lt;p&gt;Hi Jeff,&lt;/p&gt;
&lt;p&gt;Do you know if this is possible with the June 2011 CTP and EF 4.1? I&amp;#39;m getting the error below:&lt;/p&gt;
&lt;p&gt;The server encountered an error processing the request. The exception message is &amp;#39;Expression of type &amp;#39;System.Data.Objects.ObjectContext&amp;#39; cannot be used for return type &amp;#39;System.Data.Objects.ObjectContext&amp;#39;&amp;#39;. See server logs for more details. The exception stack trace is:&lt;/p&gt;
&lt;p&gt;at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression&amp;amp; body, ReadOnlyCollection`1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable`1 parameters) at System.Data.Services.Providers.DbContextHelper.CreateDbContextAccessor(Type type) at System.Data.Services.Providers.DbContextHelper.GetDbContextAccessor(Type type) at System.Data.Services.DataService`1.CreateProvider() at System.Data.Services.DataService`1.HandleRequest() at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp;amp; rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10219822" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10200516</link><pubDate>Thu, 25 Aug 2011 19:54:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10200516</guid><dc:creator>nss</dc:creator><description>&lt;p&gt;i am getting the followi&lt;/p&gt;
&lt;p&gt;&amp;#39;System.Data.Objects.ObjectContext&amp;#39; does not contain a definition for &amp;#39;Address&amp;#39; and no extension method &amp;#39;Address&amp;#39; accepting a first argument of type &amp;#39;System.Data.Objects.ObjectContext&amp;#39; could be found (are you missing a using directive or an assembly reference?)&lt;/p&gt;
&lt;p&gt;below &amp;nbsp;is my code.&lt;/p&gt;
&lt;p&gt;using System;&lt;/p&gt;
&lt;p&gt;using System.Collections.Generic;&lt;/p&gt;
&lt;p&gt;using System.Data.Services;&lt;/p&gt;
&lt;p&gt;using System.Data.Services.Common;&lt;/p&gt;
&lt;p&gt;using System.Linq;&lt;/p&gt;
&lt;p&gt;using System.ServiceModel.Web;&lt;/p&gt;
&lt;p&gt;using System.Web;&lt;/p&gt;
&lt;p&gt;using System.Data.Services.Client;&lt;/p&gt;
&lt;p&gt;using System.Data.Objects;&lt;/p&gt;
&lt;p&gt;using System.Data.Entity.Infrastructure;&lt;/p&gt;
&lt;p&gt;using CodeFirstMVC.Models;&lt;/p&gt;
&lt;p&gt;namespace eGate.BackOffice.WebClient.WCF_Services&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public class WcfDataService1 : DataService&amp;lt;ObjectContext&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// This method is called only once to initialize service-wide policies.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static void InitializeService(DataServiceConfiguration config)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;config.SetEntitySetAccessRule(&amp;quot;*&amp;quot;, EntitySetRights.All);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;protected override ObjectContext CreateDataSource()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AddressContext addrContext = new AddressContext();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Get the underlying ObjectContext for the DbContext. &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var context = ((IObjectContextAdapter)addrContext).ObjectContext;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;context.ContextOptions.ProxyCreationEnabled = false;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Return the underlying context. &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return context;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[WebGet]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public IQueryable&amp;lt;Address&amp;gt; GetAllAddress()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return CurrentDataSource.Address;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&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=10200516" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10186478</link><pubDate>Thu, 14 Jul 2011 12:10:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10186478</guid><dc:creator>Sam</dc:creator><description>&lt;p&gt;the error could be access rights on the sql database.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10186478" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10169930</link><pubDate>Tue, 31 May 2011 14:39:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10169930</guid><dc:creator>Jamie</dc:creator><description>&lt;p&gt;Does the DataService now work against an interface? Or literally types derived from ObjectContext and DataContext?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10169930" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10168247</link><pubDate>Wed, 25 May 2011 14:46:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10168247</guid><dc:creator>Sam</dc:creator><description>&lt;p&gt;I tried hosting a wcf data service using the local iis web server. whenever i try viewing the service in browser i receive the following error: Request Error - The server encountered an error processing the request. See server logs for more details. I, however, am able to access the service using the default Visual Studio Development Server&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10168247" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10161428</link><pubDate>Thu, 05 May 2011 15:41:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10161428</guid><dc:creator>Darren</dc:creator><description>&lt;p&gt;Matt, &amp;nbsp;&lt;/p&gt;
&lt;p&gt;From what I understand in order to take advantage of the database creation, you need to use SQLExpress in order to generate the initial DB.... Im not quite sure as to the reasoning behind it, but whenever I try to use the DB initialization side, on a -non-sqlexpress instance I get the same error.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10161428" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10148968</link><pubDate>Fri, 01 Apr 2011 20:48:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10148968</guid><dc:creator>william simons </dc:creator><description>&lt;p&gt;It would be nice to see a wcf ria example...Is this possible?? &amp;nbsp;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10148968" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10147710</link><pubDate>Wed, 30 Mar 2011 13:06:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10147710</guid><dc:creator>Fred</dc:creator><description>&lt;p&gt;How about somebody doing a model first, winform, datagridview, master/detail, observable example. I have spent considerable time trying to piece this together from all these blogs and I have not been successful. Seems to me this would be fairly common scenrio.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10147710" width="1" height="1"&gt;</description></item><item><title>re: Using WCF Data Services with Entity Framework 4.1 and Code First</title><link>http://blogs.msdn.com/b/adonet/archive/2011/03/21/using-wcf-data-services-with-entity-framework-4-1-and-code-first.aspx#10144992</link><pubDate>Wed, 23 Mar 2011 19:53:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10144992</guid><dc:creator>Matt</dc:creator><description>&lt;p&gt;After following along with the instructions given here, I&amp;#39;m encountering an error that I don&amp;#39;t understand. This comes up as soon as I run the service.&lt;/p&gt;
&lt;p&gt;Request Error&lt;/p&gt;
&lt;p&gt;The server encountered an error processing the request. The exception message is &amp;#39;Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.&amp;#39;.&lt;/p&gt;
&lt;p&gt;The only thing I did differently from the instructions above is to use my own connection string instead of the default (which would use SQLEXPRESS). I named the connection string the same as the context name, which I saw I would need to do from another blog. This is how it appears in the web.config:&lt;/p&gt;
&lt;p&gt;&amp;lt;add name=&amp;quot;HospitalContext&amp;quot; connectionString=&amp;quot;Data Source=LT1\DEVSQL;Initial Catalog=DEV_TEST;User ID=******;Password=******;&amp;quot; providerName=&amp;quot;System.Data.SqlClient&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;This points to an empty database with no tables, etc. I was expecting the tables corresponding to Patients and LabResults to be created in this empty database.&lt;/p&gt;
&lt;p&gt;Anyhow, if you have any recommendations I&amp;#39;d really appreciate it.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Matt&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10144992" width="1" height="1"&gt;</description></item></channel></rss>