ADO.NET Entity Framework and LINQ to Entities (Pre-Release) ForumFeedback and QnA related to Pre-Release versions of the ADO.NET Entity Framework and LINQ to Entities including object-relational mapping and entity data modeling.© 2009 Microsoft Corporation. All rights reserved.Fri, 27 Nov 2009 21:29:35 Zccd55b3f-4f39-43b7-9b3b-3f8e7415e958http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/ce992998-dc69-4e30-a806-28c0e0a577b0http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/ce992998-dc69-4e30-a806-28c0e0a577b0zeeshan hiranihttp://social.msdn.microsoft.com/Profile/en-US/?user=zeeshan%20hiranigenerate timestamp column using model first<span style="font-family:'Times New Roman';font-size:medium"> <div style="color:#000000;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:67%;background-image:initial;background-repeat:initial;background-attachment:initial;background-color:#ffffff;margin:8px">I have not figure out how to get EF model first to generate timestamp column on my table. I set the property to binary, column to computed, Fixed length but it still does not generate timestamp column when i right click and choose generate database from the model. <div><br/></div> <div>Zeeshan</div> </div> </span>Fri, 27 Nov 2009 21:29:35 Z2009-11-27T21:29:35Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/66c44977-3969-4b0b-9bc1-cd0641a4ed68http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/66c44977-3969-4b0b-9bc1-cd0641a4ed68Michael_R.http://social.msdn.microsoft.com/Profile/en-US/?user=Michael_R.ExceptionI'm having a new problem that has brought this entire project to a grinding halt again. I googled for info and found very little beyond the following thread. I've posted to it. If you have any suggestions, I'd be very greatful. This project is becoming quite the chore thanks to the EF instead of easier and other ORM solutions are begining to appeal. I'd really like to keep my tools 100% MS though :(<br/><br/><a href="http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/eb526976-868b-4070-8220-ab86720b51ee/">http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/eb526976-868b-4070-8220-ab86720b51ee/</a>Sun, 22 Nov 2009 00:08:31 Z2009-11-27T21:20:51Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/86f78f51-611d-4b1b-ba05-7fe2247a290bhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/86f78f51-611d-4b1b-ba05-7fe2247a290bKevin Dahlhttp://social.msdn.microsoft.com/Profile/en-US/?user=Kevin%20DahlEntity Key InferenceCan any tell me if there is a way around the behaviour where EF will infer any non-nullable columns as entity keys in views? I can see from the VS 2010 beta that the same inference is still happening (though it still confuses me as to WHY), but I'm not able to determine whether there is a workable solution for removing the improper inference that won't get stomped by generated code every time you update the model.<br/><br/>These are the threads in which the problem has been discussed:<br/><br/><a href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/ea0bf748-bc97-439d-99b0-76180b2161bb/">http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/ea0bf748-bc97-439d-99b0-76180b2161bb/</a><br/><br/><a href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/86f231fb-c42f-4297-83f6-5ffd4e972e47">http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/86f231fb-c42f-4297-83f6-5ffd4e972e47</a><br/><br/>Thanks for any insight that can be provided.Wed, 28 Oct 2009 22:09:33 Z2009-11-27T20:41:41Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/87e85738-2dc0-4e22-a38f-49854b24a2cchttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/87e85738-2dc0-4e22-a38f-49854b24a2ccInstrikerhttp://social.msdn.microsoft.com/Profile/en-US/?user=InstrikerUse of model defined functions on properties / methods of an entityAfter looling a little to mdf, this is something I need. The standard way seems to be this something like this : <br/> <div style="background-color:white;color:black"> <pre> &lt;Function Name=<span style="color:#a31515">&quot;IsAdult&quot;</span> ReturnType=<span style="color:#a31515">&quot;Edm.Boolean&quot;</span>&gt;<br/>  &lt;Parameter Name=<span style="color:#a31515">&quot;student&quot;</span> Type=<span style="color:#a31515">&quot;AlertesModel.Student&quot;</span> /&gt;<br/>  &lt;DefiningExpression&gt;<br/>   student.BirthDate &amp;lt;= AddYears (CurrentDateTime(), -18)<br/>  &lt;/DefiningExpression&gt;<br/> &lt;/Function&gt;<br/><span style="color:blue"> <br/> public</span> <span style="color:blue">static</span> <span style="color:blue">class</span> EFFunctions<br/>   {<br/>      [System.Data.Objects.DataClasses.EdmFunction (<span style="color:#a31515">&quot;Model&quot;</span>, <span style="color:#a31515">&quot;IsAdult&quot;</span>)]<br/>      <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">bool</span> IsAdult (Student Student)<br/>      {<br/>         <span style="color:blue">throw</span> <span style="color:blue">new</span> NotSupportedException (<span style="color:#a31515">&quot;Direct calls are not supported.&quot;</span>);<br/>      }<br/>   }<br/><br/><br/><br/>   <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">int</span> GetStudentsAdultCount ()<br/>   {<br/>      <span style="color:blue">using</span> (ModelContainer context = <span style="color:blue">new</span> ModelContainer ())<br/>      {<br/>         <span style="color:blue">var</span> query =<br/>            <span style="color:blue">from</span> e <span style="color:blue">in</span> context.Students<br/>            <span style="color:blue">where</span> EFFunctions.IsAdult (e)<br/>            <span style="color:blue">select</span> e;<br/>         <span style="color:blue">return</span> query.Count ();<br/>      }<br/>   } </pre> </div> With extensions methods, we can do a little better when building Linq To Entity queries : <br/><br/> <div style="background-color:white;color:black"> <pre> <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">class</span> EFFunctions { [System.Data.Objects.DataClasses.EdmFunction (<span style="color:#a31515">&quot;Model&quot;</span>, <span style="color:#a31515">&quot;IsAdult&quot;</span>)] <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">bool</span> IsAdult (<span style="color:blue">this</span> Student Student) { <span style="color:blue">throw</span> <span style="color:blue">new</span> NotSupportedException (<span style="color:#a31515">&quot;Direct calls are not supported.&quot;</span>); } } <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">int</span> GetStudentsAdultCount () { <span style="color:blue">using</span> (ModelContainer context = <span style="color:blue">new</span> ModelContainer ()) { <span style="color:blue">var</span> query = <span style="color:blue">from</span> e <span style="color:blue">in</span> context.Students <span style="color:blue">where</span> e.IsAdult () <span style="color:blue">select</span> e; <span style="color:blue">return</span> query.Count (); } } </pre> </div> But this could be nicer if we could define the function inside the entity class instead of &quot;MyCustomsFunctions&quot; class like this :<br/><br/> <div style="background-color:white;color:black"> <pre> &lt;Function Name=<span style="color:#a31515">&quot;IsAdult&quot;</span> ReturnType=<span style="color:#a31515">&quot;Edm.Boolean&quot;</span>&gt; &lt;DefiningExpression&gt; it.BirthDate &amp;lt;= AddYears (CurrentDateTime(), -18) &lt;/DefiningExpression&gt; &lt;/Function&gt; <span style="color:blue">public</span> <span style="color:blue">class</span> Student { [System.Data.Objects.DataClasses.EdmFunction (<span style="color:#a31515">&quot;Model&quot;</span>, <span style="color:#a31515">&quot;IsAdult&quot;</span>)] <span style="color:blue">public</span> <span style="color:blue">bool</span> IsAdult { <span style="color:blue">get</span> { <span style="color:blue">throw</span> <span style="color:blue">new</span> NotSupportedException (<span style="color:#a31515">&quot;Direct calls are not supported.&quot;</span>); } } <span style="color:green">// Or</span> [System.Data.Objects.DataClasses.EdmFunction (<span style="color:#a31515">&quot;Model&quot;</span>, <span style="color:#a31515">&quot;IsAdult&quot;</span>)] <span style="color:blue">public</span> <span style="color:blue">bool</span> IsAdult () { <span style="color:blue">throw</span> <span style="color:blue">new</span> NotSupportedException (<span style="color:#a31515">&quot;Direct calls are not supported.&quot;</span>); } } <span style="color:blue">public</span> <span style="color:blue">static</span> <span style="color:blue">int</span> GetStudentsAdultCount () { <span style="color:blue">using</span> (ModelContainer context = <span style="color:blue">new</span> ModelContainer ()) { <span style="color:blue">var</span> query = <span style="color:blue">from</span> e <span style="color:blue">in</span> context.Students <span style="color:blue">where</span> e.IsAdult <span style="color:green">// Or e.IsAdult ()</span> <span style="color:blue">select</span> e; <span style="color:blue">return</span> query.Count (); } } </pre> </div> So with extension methods, it's nice, but is there any way to do something better ?<br/>- Keep the Linq Query syntaxe using &quot;e.XXXX&quot; instead of &quot;EFFunctions.XXXX&quot;<br/>- Declare the EdmFunction  inside the entity class (we can't do extension methods on non-static classes).Fri, 27 Nov 2009 15:59:07 Z2009-11-27T15:59:08Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/ab3ee3e7-d822-49ca-8364-898c9a2a06c5http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/ab3ee3e7-d822-49ca-8364-898c9a2a06c5Alexey Rokhinhttp://social.msdn.microsoft.com/Profile/en-US/?user=Alexey%20RokhinAllow custom attrubutes for entity objects to be created using designerPlease allow custom attributes (similar to .Net custom attributes) for entity types, properties, navigation properties, associations etc to be created using entity designer.<br/>Ideally I would have the ability to create dictionary of custom attributes for model (may be restricting attributes to concrete targets: types, properties etc) and to apply these attributes to concrete objects.<br/>Then I wish to use these attributes in custom tt-file to customize code generation.<br/>Sometimes it would be useful to define some properties of the attributes (for example Value) to have additional flexibility in code generation.Fri, 27 Nov 2009 15:40:27 Z2009-11-27T15:40:27Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/1f5088fb-39d0-4e53-85bf-98bfa11bb911http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/1f5088fb-39d0-4e53-85bf-98bfa11bb911JulioNEThttp://social.msdn.microsoft.com/Profile/en-US/?user=JulioNETEDM4 with POCO x WebServiceI have a problem with this code:<br/><br/>My class:<br/>public class People()<br/>{<br/>    private List&lt;People&gt; _peopleparent = new List&lt;People&gt;();<br/><br/>    public virtual int Id { get; set; };<br/>    public virtual string Name  { get; set; }<br/>    public virtual int? ParentId { get; set; }<br/>    public virtual People Parent { get; set; }<br/>    public virtual List&lt;People&gt; PeopleParent<br/>    {<br/>        get { return _peopleparent; }<br/>        set { _peopleparent = value; }<br/>    }<br/>}<br/><br/>My webservice:<br/>public class PeopleWS : System.Web.Services.WebService<br/>{<br/>    ModelContext db = new ModelContext();<br/><br/>    [WebMethod]<br/>    public List&lt;People&gt; SelectAll()<br/>    {<br/>        return (from q in db.People select q).ToList();<br/>    }<br/>}<br/><br/>The error when I execute the webservice:<br/>System.InvalidOperationException: There was an error generating the XML document. ---&gt; System.InvalidOperationException: A circular reference was detected while serializing an object of type PeopleWS.People.<br/><br/>Tue, 17 Nov 2009 14:17:13 Z2009-11-26T23:21:15Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/6920db2b-88c7-4bea-ac89-4809882cff8fhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/6920db2b-88c7-4bea-ac89-4809882cff8fmighty__manhttp://social.msdn.microsoft.com/Profile/en-US/?user=mighty__manCodeOnly ManyToManyLets say that I have simple model with a ManyToMany relation between Foos and Bars.<br/>If the model has Foo.Bars and Bar.Foos it´s simple to config a relation and a BarFoo table.<br/><br/> <pre lang="x-c#">Relationship(f =&gt; f.Bars).FromProperty(b =&gt; b.Foos);</pre> But what if I would like the DB to have ManyToMany but it ain´t reflected in the model.<br/>So Foo no longer has the Foo.Bars collection.<br/><br/>If I configure this using Map to set up a relation table with Foo.Id and Bar.Id I get a table with one of the Id´s as Primary key.<br/><br/> <pre lang="x-c#">Relationship(b =&gt; b.Foos).Map(new StoreTableName(&quot;BarFoo&quot;, &quot;dbo&quot;), (b, f) =&gt; new { barId = b.Id, fooId = f.Id });</pre> How do I set up this scenario with CodeOnly to get both Id as combined Key ?<br/><br/>Tue, 17 Nov 2009 18:06:39 Z2009-11-26T09:45:26Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/0fdabbe2-b82d-47f2-8d81-c9023f6c1d4dhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/0fdabbe2-b82d-47f2-8d81-c9023f6c1d4dAlexey Rokhinhttp://social.msdn.microsoft.com/Profile/en-US/?user=Alexey%20RokhinOnce again about large model splitting<p>I've read about current approach to large model splitting (<a href="http://blogs.msdn.com/adonet/archive/2008/11/25/working-with-large-models-in-entity-framework-part-2.aspx">here</a>).<br/><br/>When using model(s) from another model (and having inheritance, association and navigation properties between different models) will be available through designer? Also it would be great to have abilty to choose subset of objects from &quot;used&quot; model which will be placed on another model designer surface.<br/><br/>When multiple designer windows are planned to be implemented (this question was asked <a href="http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/dd397d91-436c-412e-8f9d-3cdcebbb8d40">here</a>)?<br/><br/>Thank you.</p>Thu, 26 Nov 2009 09:13:45 Z2009-11-26T09:13:45Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/862abdae-b63f-45f5-8a6c-0bdd6eeabfdbhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/862abdae-b63f-45f5-8a6c-0bdd6eeabfdbMarcelNihttp://social.msdn.microsoft.com/Profile/en-US/?user=MarcelNiGetting SqlException "Invalid column name 'User_Id' from EF4 code-only I got a strange behaviour with code only (EF CTP) where I get an EntityCommandExecutionException, and the inner exception is a SQLException saying: Invalid column name 'User_Id'.<br/><br/>The strange thing with this is that my POCO does not contain a User_Id (there is even no such field/property in my whole solution).<br/><br/>Here is the stack trace from the EntityCommandExecutionException:<br/><br/>   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)<br/>   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)<br/>   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)<br/>   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator()<br/>   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)<br/>   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)<br/>   at Repositories.EF.EFRepository`2.GetAll() in C:\Projects\Repositories.EF\EFRepository.vb:line 64<br/>   at epositories.Website.EFBlogAggregateRepository.GetAllBlogs() in C:\Projects\Repositories.Website\EntityFramework\Repositories\AggregateRepositories\EFBlogAggregateRepository.vb:line 18<br/>   at Repositories.Test.BlogTest.GetAllBlogs() in C:\Projects\Repositories.Test\BlogTest.vb:line 70<br/><br/>Does anybody have an idea what is going on here?Tue, 24 Nov 2009 13:27:04 Z2009-11-26T03:05:09Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/3a1a9e65-be4b-4c60-a616-0b28f7154c7fhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/3a1a9e65-be4b-4c60-a616-0b28f7154c7fJames Alexanderhttp://social.msdn.microsoft.com/Profile/en-US/?user=James%20AlexanderAm I missing Code Generation Items for Beta 2 and the Feature CTP?After seeing EF4 shown off at PDC last week, I want to experiment w/ EF4's POCO support. I installed the Feature CTP, I created a new C# Class Library, added an EDM, and set the code generation strategy to &quot;None&quot;. When I right click inside the model though and click Add Code Generation Item, I'm only presented w/ two options, &quot;ADO.NET EntityObject Generator&quot; and &quot;ADO.NET Self-Tracking Entity Generator&quot;.<br/><br/>During the session I attended at PDC, I remember seeing a few more than this and along with those, there was an item for generating POCO's. Is there something in additional to Beta 2 and the Feature CTP that I need to install to get this Code Generation Item?<hr class="sig">Blades Don't Need Reloading...Tue, 24 Nov 2009 14:07:29 Z2009-11-25T19:15:39Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/3963bd74-7a09-42a5-9589-a4a94976ccc4http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/3963bd74-7a09-42a5-9589-a4a94976ccc4ExecuteFunction throws exception EF4 CTP2http://social.msdn.microsoft.com/Profile/en-US/?user=ExecuteFunction%20throws%20exception%20EF4%20CTP2ExecuteFunction throws exception EF4 CTP2I was able to replicate this on two computers<br/>I have a simple stored procedure<br/><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>CREATE</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">PROCEDURE</span></span><span style="font-size:x-small"> checkstate @param </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">varchar</span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">(</span></span><span style="font-size:x-small">11</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">)<br/></span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS<br/></span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">RETURN</span></span><span style="font-size:x-small"> 1<br/></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">GO<br/><br/>In my EDMX I imported it as Function checkstate<br/><br/>Return Scalar Int32 (when I click Get Column Info. it says correctly &quot;The selected stored procedure returns no columns&quot;)<br/>but when I call <br/><br/><span style="font-family:Consolas;font-size:x-small"><span style="font-family:Consolas;font-size:x-small"><font face=Consolas size=2><font face=Consolas size=2> <p> </p> </font></font></span><font face=Consolas size=2> <p> </p> </font></span> <p><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small">static</span></span></span><span style="font-family:Consolas;font-size:x-small"><span style="font-family:Consolas;font-size:x-small"> </span></span><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small">void</span></span></span><span style="font-family:Consolas;font-size:x-small"><span style="font-family:Consolas;font-size:x-small"> Main(</span></span><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small">string</span></span></span><span style="font-family:Consolas;font-size:x-small"><span style="font-family:Consolas;font-size:x-small">[] args)<font face=Consolas size=2><font face=Consolas size=2> <p>{</p> </font></font></span><font face=Consolas size=2> <p> </p> </font></span></p> <p><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small">   using</span></span></span><span style="font-family:Consolas;font-size:x-small"><span style="font-family:Consolas;font-size:x-small"> (</span></span><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small">var</span></span></span><span style="font-family:Consolas;font-size:x-small"><span style="font-family:Consolas;font-size:x-small"> model = </span></span><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small"><span style="font-family:Consolas;color:#0000ff;font-size:x-small">new</span></span></span><span style="font-family:Consolas;font-size:x-small"><span style="font-family:Consolas;font-size:x-small"> SystemEntities())<br/>   {<br/>      model.checkstate(</span></span><span style="font-family:Consolas;color:#a31515;font-size:x-small"><span style="font-family:Consolas;color:#a31515;font-size:x-small"><span style="font-family:Consolas;color:#a31515;font-size:x-small">&quot;anything&quot;</span></span></span><span style="font-family:Consolas;font-size:x-small"><span style="font-family:Consolas;font-size:x-small">);<br/>   }<br/>}<font face=Consolas size=2><font face=Consolas size=2> <p> </p> </font></font></span><font face=Consolas size=2> <p> </p> </font></span></p> <p>it throws exception <br/>The data reader returned by the store data provider does not have enough columns for the query requested.<br/><br/>I can replacate this on two different machines (different dbs too) Can anyone help?<br/><br/>Thank you</p> </span></span></p>Tue, 24 Nov 2009 15:47:41 Z2009-11-25T19:12:14Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/3abc503b-22c8-4397-8e1a-b1203b071941http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/3abc503b-22c8-4397-8e1a-b1203b071941Alexey Zakharovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Alexey%20ZakharovAdd expression based version to include operatorCurrently new EF 4.0 has context.LoadProperty method which uses expression syntax to get property name.<br/> <br/> I think you should add the same overload to ObjectQuery Include method. <br/> <br/> Example:<br/> products.Include(p =&gt; p.Tags)Tue, 24 Nov 2009 10:24:06 Z2009-11-25T18:54:32Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/cf51b438-c06b-4f8e-9335-6bc0c2d2132ehttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/cf51b438-c06b-4f8e-9335-6bc0c2d2132eAlexey Rokhinhttp://social.msdn.microsoft.com/Profile/en-US/?user=Alexey%20RokhinSQL code for Any extension method optimizationSeems that t-sql query simplification and optimization may be implemented for method Any.<br/>Now for code<br/>bool v = p.Objects.Any(o =&gt; o.Id &lt; 0);<br/>this T-SQL code is generated<br/>SELECT <br/>CASE WHEN ( EXISTS (SELECT <br/> 1 AS [C1]<br/> FROM [dbo].[Objects] AS [Extent1]<br/> WHERE [Extent1].[ID] &lt; 0<br/>)) THEN cast(1 as bit) WHEN ( NOT EXISTS (SELECT <br/> 1 AS [C1]<br/> FROM [dbo].[Objects] AS [Extent2]<br/> WHERE [Extent2].[ID] &lt; 0<br/>)) THEN cast(0 as bit) END AS [C1]<br/>FROM  ( SELECT 1 AS X ) AS [SingleRowTable1]<br/><br/>Second when (with NOT EXISTS) is not required. It may be replaced with else:<br/>SELECT <br/>CASE WHEN ( EXISTS (SELECT <br/> 1 AS [C1]<br/> FROM [dbo].[Objects] AS [Extent1]<br/> WHERE [Extent1].[ID] &lt; 0<br/>)) THEN cast(1 as bit)<br/>ELSE cast(0 as bit) END AS [C1]<br/>FROM  ( SELECT 1 AS X ) AS [SingleRowTable1]<br/><br/>Also I believe that this variant is more reliable. Imagine that there were not rows with Id&lt;0 when first WHEN was checked (check result is false). After it second WHEN is being checked. But before this check (and after first check) one or several rows with Id &lt; 0 were added (if you not use SERIALIZABLE isolation level). Then second WHEN will be false and <strong>implicit</strong> ELSE will be executed. This else will return NULL. I suppose (not sure) that will be exception.Wed, 25 Nov 2009 15:53:48 Z2009-11-25T18:48:30Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/60bbff42-dbbc-4b7c-9a2f-b4a78d4b5fechttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/60bbff42-dbbc-4b7c-9a2f-b4a78d4b5fecKen Smithhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ken%20SmithThe EntityReference object could not be serializedI have an n-tier solution using Silverlight/WCF/Entity Framework that I recently upgraded from .NET 3.5 to .NET 4.0 (beta 2).  In one of my test methods (in a separate project which calls the WCF service), I have the following code: <div><span style="background-color:#ffffff"><br/></span></div> <div><span style="background-color:#ffffff"> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">private</span> SharedFile CreateSharedFile(Room room, User user) { <span style="color:Blue">string</span> originalFileLocation = <span style="color:#A31515">@&quot;c:\SharedFiles\&quot;</span> + Guid.NewGuid() + <span style="color:#A31515">@&quot;\somefilename.txt&quot;</span>; SharedFile sharedFile = <span style="color:Blue">new</span> SharedFile() { SharedFileId = Guid.NewGuid(), OriginalFileLocation = originalFileLocation, OriginalFileUploadedOn = DateTime.Now, OriginalFileName = <span style="color:#A31515">&quot;somefilename.txt&quot;</span> }; sharedFile.ConvertedFileUri = <span style="color:#A31515">&quot;http://localhost/somefilename.txt&quot;</span>; sharedFile.ConvertedFileTypeId = <span style="color:#A31515">&quot;Text&quot;</span>; sharedFile.User = user; sharedFile = roomService.CreateSharedFile(sharedFile); <span style="color:Blue">return</span> sharedFile; } </pre> </div> </span></div> <div><span style="background-color:#ffffff"><br/></span></div> <div><span style="background-color:#ffffff">Under EF V1/NET 3.5, this worked fine.  However, now it's throwing this error (on the roomService.CreateSharedFile(sharedFile) line):</span></div> <div><span style="background-color:#ffffff"><br/></span></div> <div>System.InvalidOperationException: The EntityReference object could not be serialized. This type of object cannot be serialized when the RelationshipManager belongs to an entity object that does not implement IEntityWithRelationships.</div> <div><br/></div> <div>It's certainly not the most unintelligible error message that I've received, but it's maybe in the top 20.  And Google searches -- err, sorry, Bing searches -- aren't returning anything related to that error.  I'm specifically confused about the reference to RelationshipManager/IEntityWithRelationships, because the &quot;SharedFile&quot; class in question is generated by the Add Service Reference dialog box, so I'm not sure how/when/where it could need to deal with EF relationships.</div> <div><br/></div> <div>Any thoughts about what's going wrong?</div> <hr class=sig> Ken SmithWed, 25 Nov 2009 07:40:36 Z2009-11-25T18:00:13Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/06064765-3d93-4928-998d-1ed7695839a3http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/06064765-3d93-4928-998d-1ed7695839a3Instrikerhttp://social.msdn.microsoft.com/Profile/en-US/?user=InstrikerBug when using stored proc to update multiples children entitiesWhen I change multiples children entities instances and their update is mapped to a stored proc, I get an Update Exception : Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.<br/><br/>But if I update only 1 child or remove the stored proc mapping, all goes well.<br/><br/>Here is the code to reproduce the bug:<br/><br/> <pre lang="x-c#">using System; using System.Data; using System.Linq; namespace ConsoleApplication1 { class Program { static void Main (string[] args) { using (TestEntities context = new TestEntities ()) { var toUpdate = (from t in context.Composant.Include (&quot;Descriptions&quot;) select t).First (); int nbrUpdates = 0; foreach (var description in toUpdate.Descriptions) { description.Description = &quot;new description &quot; + Guid.NewGuid ().ToString (); nbrUpdates++; } if (nbrUpdates &lt; 2) throw new InvalidOperationException (&quot;Cannot reproduce bug with only 1 update.&quot;); try { context.SaveChanges (); } catch (UpdateException exc) { throw new InvalidOperationException (&quot;Bug reproduced.&quot;, exc); } } } } }</pre> And this is the edmx file :<br/><br/> <pre lang=x-xml>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;edmx:Edmx Version=&quot;2.0&quot; xmlns:edmx=&quot;http://schemas.microsoft.com/ado/2008/10/edmx&quot;&gt; &lt;edmx:Runtime&gt; &lt;!-- SSDL content --&gt; &lt;edmx:StorageModels&gt; &lt;Schema Namespace=&quot;TestStoreNamespace&quot; Alias=&quot;Self&quot; Provider=&quot;System.Data.SqlClient&quot; ProviderManifestToken=&quot;2005&quot; xmlns:store=&quot;http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator&quot; xmlns=&quot;http://schemas.microsoft.com/ado/2009/02/edm/ssdl&quot;&gt; &lt;EntityContainer Name=&quot;TestStoreNamespaceContainer&quot;&gt; &lt;EntitySet Name=&quot;Composant&quot; EntityType=&quot;TestStoreNamespace.Composant&quot; store:Type=&quot;Tables&quot; Schema=&quot;dbo&quot; /&gt; &lt;EntitySet Name=&quot;ComposantDescr&quot; EntityType=&quot;TestStoreNamespace.ComposantDescr&quot; store:Type=&quot;Tables&quot; Schema=&quot;dbo&quot; /&gt; &lt;AssociationSet Name=&quot;FK_dbo_ComposantDescr_dbo_Composant&quot; Association=&quot;TestStoreNamespace.FK_dbo_ComposantDescr_dbo_Composant&quot;&gt; &lt;End Role=&quot;Composant&quot; EntitySet=&quot;Composant&quot; /&gt; &lt;End Role=&quot;ComposantDescr&quot; EntitySet=&quot;ComposantDescr&quot; /&gt; &lt;/AssociationSet&gt; &lt;/EntityContainer&gt; &lt;EntityType Name=&quot;Composant&quot;&gt; &lt;Key&gt; &lt;PropertyRef Name=&quot;IdComposant&quot; /&gt; &lt;/Key&gt; &lt;Property Name=&quot;IdComposant&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt; &lt;/EntityType&gt; &lt;EntityType Name=&quot;ComposantDescr&quot;&gt; &lt;Key&gt; &lt;PropertyRef Name=&quot;IdComposant&quot; /&gt; &lt;PropertyRef Name=&quot;TypeDescription&quot; /&gt; &lt;/Key&gt; &lt;Property Name=&quot;IdComposant&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt; &lt;Property Name=&quot;TypeDescription&quot; Type=&quot;int&quot; Nullable=&quot;false&quot; /&gt; &lt;Property Name=&quot;Description&quot; Type=&quot;nvarchar(max)&quot; /&gt; &lt;/EntityType&gt; &lt;Association Name=&quot;FK_dbo_ComposantDescr_dbo_Composant&quot;&gt; &lt;End Role=&quot;Composant&quot; Type=&quot;TestStoreNamespace.Composant&quot; Multiplicity=&quot;1&quot;&gt; &lt;OnDelete Action=&quot;Cascade&quot; /&gt; &lt;/End&gt; &lt;End Role=&quot;ComposantDescr&quot; Type=&quot;TestStoreNamespace.ComposantDescr&quot; Multiplicity=&quot;*&quot; /&gt; &lt;ReferentialConstraint&gt; &lt;Principal Role=&quot;Composant&quot;&gt; &lt;PropertyRef Name=&quot;IdComposant&quot; /&gt; &lt;/Principal&gt; &lt;Dependent Role=&quot;ComposantDescr&quot;&gt; &lt;PropertyRef Name=&quot;IdComposant&quot; /&gt; &lt;/Dependent&gt; &lt;/ReferentialConstraint&gt; &lt;/Association&gt; &lt;Function Name=&quot;sp_ComposantDescr_U&quot; Aggregate=&quot;false&quot; BuiltIn=&quot;false&quot; NiladicFunction=&quot;false&quot; IsComposable=&quot;false&quot; ParameterTypeSemantics=&quot;AllowImplicitConversion&quot; Schema=&quot;dbo&quot;&gt; &lt;Parameter Name=&quot;pId&quot; Type=&quot;int&quot; Mode=&quot;In&quot; /&gt; &lt;Parameter Name=&quot;pTypeDescription&quot; Type=&quot;int&quot; Mode=&quot;In&quot; /&gt; &lt;Parameter Name=&quot;pDescription&quot; Type=&quot;nvarchar(max)&quot; Mode=&quot;In&quot; /&gt; &lt;/Function&gt; &lt;/Schema&gt;&lt;/edmx:StorageModels&gt; &lt;!-- CSDL content --&gt; &lt;edmx:ConceptualModels&gt; &lt;Schema Namespace=&quot;TestNamespace&quot; Alias=&quot;Self&quot; xmlns=&quot;http://schemas.microsoft.com/ado/2008/09/edm&quot;&gt; &lt;EntityContainer Name=&quot;TestEntities&quot;&gt; &lt;EntitySet Name=&quot;Composant&quot; EntityType=&quot;TestNamespace.Composant&quot; /&gt; &lt;EntitySet Name=&quot;ComposantDescr&quot; EntityType=&quot;TestNamespace.ComposantDescr&quot; /&gt; &lt;AssociationSet Name=&quot;FK_dbo_ComposantDescr_dbo_Composant&quot; Association=&quot;TestNamespace.FK_dbo_ComposantDescr_dbo_Composant&quot;&gt; &lt;End Role=&quot;Composant&quot; EntitySet=&quot;Composant&quot; /&gt; &lt;End Role=&quot;ComposantDescr&quot; EntitySet=&quot;ComposantDescr&quot; /&gt;&lt;/AssociationSet&gt; &lt;/EntityContainer&gt; &lt;EntityType Name=&quot;Composant&quot;&gt; &lt;Key&gt; &lt;PropertyRef Name=&quot;IdComposant&quot; /&gt; &lt;/Key&gt; &lt;Property Type=&quot;Int32&quot; Name=&quot;IdComposant&quot; Nullable=&quot;false&quot; /&gt; &lt;NavigationProperty Name=&quot;Descriptions&quot; Relationship=&quot;TestNamespace.FK_dbo_ComposantDescr_dbo_Composant&quot; FromRole=&quot;Composant&quot; ToRole=&quot;ComposantDescr&quot; /&gt; &lt;/EntityType&gt; &lt;EntityType Name=&quot;ComposantDescr&quot;&gt; &lt;Key&gt; &lt;PropertyRef Name=&quot;IdComposant&quot; /&gt; &lt;PropertyRef Name=&quot;TypeDescription&quot; /&gt; &lt;/Key&gt; &lt;Property Type=&quot;Int32&quot; Name=&quot;IdComposant&quot; Nullable=&quot;false&quot; /&gt; &lt;Property Type=&quot;Int32&quot; Name=&quot;TypeDescription&quot; Nullable=&quot;false&quot; /&gt; &lt;Property Type=&quot;String&quot; Name=&quot;Description&quot; MaxLength=&quot;Max&quot; FixedLength=&quot;false&quot; Unicode=&quot;true&quot; /&gt; &lt;NavigationProperty Name=&quot;Composant&quot; Relationship=&quot;TestNamespace.FK_dbo_ComposantDescr_dbo_Composant&quot; FromRole=&quot;ComposantDescr&quot; ToRole=&quot;Composant&quot; /&gt; &lt;/EntityType&gt; &lt;Association Name=&quot;FK_dbo_ComposantDescr_dbo_Composant&quot;&gt; &lt;End Type=&quot;TestNamespace.Composant&quot; Role=&quot;Composant&quot; Multiplicity=&quot;1&quot; &gt; &lt;OnDelete Action=&quot;Cascade&quot; /&gt;&lt;/End&gt; &lt;End Type=&quot;TestNamespace.ComposantDescr&quot; Role=&quot;ComposantDescr&quot; Multiplicity=&quot;*&quot; &gt; &lt;/End&gt; &lt;ReferentialConstraint&gt; &lt;Principal Role=&quot;Composant&quot;&gt; &lt;PropertyRef Name=&quot;IdComposant&quot; /&gt;&lt;/Principal&gt; &lt;Dependent Role=&quot;ComposantDescr&quot;&gt; &lt;PropertyRef Name=&quot;IdComposant&quot; /&gt;&lt;/Dependent&gt;&lt;/ReferentialConstraint&gt;&lt;/Association&gt; &lt;/Schema&gt; &lt;/edmx:ConceptualModels&gt; &lt;!-- C-S mapping content --&gt; &lt;edmx:Mappings&gt; &lt;Mapping Space=&quot;C-S&quot; xmlns=&quot;http://schemas.microsoft.com/ado/2008/09/mapping/cs&quot;&gt; &lt;EntityContainerMapping StorageEntityContainer=&quot;TestStoreNamespaceContainer&quot; CdmEntityContainer=&quot;TestEntities&quot;&gt; &lt;EntitySetMapping Name=&quot;Composant&quot;&gt; &lt;EntityTypeMapping TypeName=&quot;IsTypeOf(TestNamespace.Composant)&quot;&gt; &lt;MappingFragment StoreEntitySet=&quot;Composant&quot;&gt; &lt;ScalarProperty Name=&quot;IdComposant&quot; ColumnName=&quot;IdComposant&quot; /&gt; &lt;/MappingFragment&gt; &lt;/EntityTypeMapping&gt; &lt;/EntitySetMapping&gt; &lt;EntitySetMapping Name=&quot;ComposantDescr&quot;&gt; &lt;EntityTypeMapping TypeName=&quot;IsTypeOf(TestNamespace.ComposantDescr)&quot;&gt; &lt;MappingFragment StoreEntitySet=&quot;ComposantDescr&quot;&gt; &lt;ScalarProperty Name=&quot;IdComposant&quot; ColumnName=&quot;IdComposant&quot; /&gt; &lt;ScalarProperty Name=&quot;TypeDescription&quot; ColumnName=&quot;TypeDescription&quot; /&gt; &lt;ScalarProperty Name=&quot;Description&quot; ColumnName=&quot;Description&quot; /&gt; &lt;/MappingFragment&gt; &lt;/EntityTypeMapping&gt; &lt;EntityTypeMapping TypeName=&quot;TestNamespace.ComposantDescr&quot;&gt; &lt;ModificationFunctionMapping&gt; &lt;UpdateFunction FunctionName=&quot;TestStoreNamespace.sp_ComposantDescr_U&quot; &gt; &lt;ScalarProperty Name=&quot;Description&quot; ParameterName=&quot;pDescription&quot; Version=&quot;Current&quot; /&gt; &lt;ScalarProperty Name=&quot;TypeDescription&quot; ParameterName=&quot;pTypeDescription&quot; Version=&quot;Original&quot; /&gt; &lt;ScalarProperty Name=&quot;IdComposant&quot; ParameterName=&quot;pId&quot; Version=&quot;Original&quot; /&gt;&lt;/UpdateFunction&gt;&lt;/ModificationFunctionMapping&gt;&lt;/EntityTypeMapping&gt; &lt;/EntitySetMapping&gt; &lt;/EntityContainerMapping&gt; &lt;/Mapping&gt;&lt;/edmx:Mappings&gt; &lt;/edmx:Runtime&gt; &lt;Designer xmlns=&quot;http://schemas.microsoft.com/ado/2008/10/edmx&quot;&gt; &lt;Connection&gt; &lt;DesignerInfoPropertySet&gt; &lt;DesignerProperty Name=&quot;MetadataArtifactProcessing&quot; Value=&quot;EmbedInOutputAssembly&quot; /&gt; &lt;/DesignerInfoPropertySet&gt; &lt;/Connection&gt; &lt;Options&gt; &lt;DesignerInfoPropertySet&gt; &lt;DesignerProperty Name=&quot;ValidateOnBuild&quot; Value=&quot;False&quot; /&gt; &lt;DesignerProperty Name=&quot;EnablePluralization&quot; Value=&quot;False&quot; /&gt; &lt;DesignerProperty Name=&quot;IncludeForeignKeysInModel&quot; Value=&quot;True&quot; /&gt; &lt;/DesignerInfoPropertySet&gt; &lt;/Options&gt; &lt;Diagrams&gt; &lt;Diagram Name=&quot;TestEntities&quot; ZoomLevel=&quot;95&quot;&gt; &lt;EntityTypeShape EntityType=&quot;TestNamespace.Composant&quot; Width=&quot;2.125&quot; PointX=&quot;3.25&quot; PointY=&quot;1.625&quot; Height=&quot;1.4033821614583339&quot; /&gt; &lt;EntityTypeShape EntityType=&quot;TestNamespace.ComposantDescr&quot; Width=&quot;1.75&quot; PointX=&quot;7.375&quot; PointY=&quot;1.375&quot; Height=&quot;1.787985026041667&quot; /&gt; &lt;AssociationConnector Association=&quot;TestNamespace.FK_dbo_ComposantDescr_dbo_Composant&quot; &gt; &lt;ConnectorPoint PointX=&quot;5.375&quot; PointY=&quot;2.3266910807291667&quot; /&gt; &lt;ConnectorPoint PointX=&quot;7.375&quot; PointY=&quot;2.3266910807291667&quot; /&gt;&lt;/AssociationConnector&gt; &lt;/Diagram&gt; &lt;/Diagrams&gt; &lt;/Designer&gt; &lt;/edmx:Edmx&gt;</pre> and the T-Sql code for SqlExpress to create the database with datas :<br/><br/> <pre lang=x-sql>CREATE TABLE [dbo].[Composant] ( [IdComposant] int NOT NULL ) GO CREATE TABLE [dbo].[ComposantDescr] ( [IdComposant] int NOT NULL, [TypeDescription] int NOT NULL, [Description] nvarchar(max) NULL ) GO ALTER TABLE [dbo].[Composant] WITH NOCHECK ADD CONSTRAINT [PK_Composant] PRIMARY KEY CLUSTERED ([IdComposant] ASC) GO ALTER TABLE [dbo].[ComposantDescr] WITH NOCHECK ADD CONSTRAINT [PK_ComposantDescr] PRIMARY KEY CLUSTERED ([IdComposant], [TypeDescription] ASC) GO ALTER TABLE [dbo].[ComposantDescr] WITH NOCHECK ADD CONSTRAint [FK_dbo_ComposantDescr_dbo_Composant] FOREIGN KEY ([IdComposant]) REFERENCES [dbo].[Composant] ([IdComposant]) ON DELETE CASCADE ON UPDATE CASCADE GO Create PROCEDURE [dbo].[sp_ComposantDescr_U] @pId int, @pTypeDescription int, @pDescription nvarchar(max) AS BEGIN SET NOCOUNT ON; -- Sample stored proc, the real one has more complexities Update Upd Set Description = @pDescription From dbo.ComposantDescr Upd Where Upd.IdComposant = @pId And Upd.TypeDescription = @pTypeDescription END GO INSERT INTO [Test].[dbo].[Composant] ([IdComposant]) VALUES (1) GO INSERT INTO [Test].[dbo].[ComposantDescr] ([IdComposant] ,[TypeDescription] ,[Description]) VALUES (1 ,0 ,'0 description') GO INSERT INTO [Test].[dbo].[ComposantDescr] ([IdComposant] ,[TypeDescription] ,[Description]) VALUES (1 ,2 ,'2 description') GO<br/></pre> <br/>So how can I solve this problem? We are using lot of stored proc to update / insert / delete int our descriptions tables, and this is a big problem for us.Wed, 21 Oct 2009 13:40:35 Z2009-11-25T12:32:56Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/2b4a2756-20c7-4a00-9c5a-c5fcb60c8457http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/2b4a2756-20c7-4a00-9c5a-c5fcb60c8457Alexey Zakharovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Alexey%20ZakharovEF POCO in n-TierHi,<br/> <br/> We are trying to use EF POCO entities in WCF:<br/> <br/> 1. first problem we faced is that entities cannot be send if cotnext proxy generation option is not disabled.<br/> 2. ApplyCurrentValues doesn't persist ref properties (ICollection&lt;Tag&gt;, Product etc). It only saves changes of value properies.Wed, 25 Nov 2009 10:32:35 Z2009-11-25T18:49:40Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/0f14d2f9-edcd-42d7-bad0-a93b70aa3f5bhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/0f14d2f9-edcd-42d7-bad0-a93b70aa3f5bJiri {x2} Cincurahttp://social.msdn.microsoft.com/Profile/en-US/?user=Jiri%20%7bx2%7d%20CincuraExplicit transactions (with custom settings)Hi *,<br/><br/>sometimes you may need to set up transaction in your database in a very precise way, using all power of favorite engine. Sadly it's not possible now. If you write something like (I know, this case I can make work via i.e. TransactionScope easily):<br/> <pre lang="x-c#">ent.Connection.Open(); IDbTransaction tx = ((ent.Connection as EntityConnection).StoreConnection as SqlConnection).BeginTransaction(IsolationLevel.Serializable); ent.MASTER.ToArray(); tx.Commit();</pre> You end up with nice exception ;), because there was a transaction, but wasn't assigned to command used for the query. Are there any plans to address this issue? Maybe we can discuss here some ideas as the transactions are core part of RDBMSs.<hr class="sig">Jiri {x2} CincuraWed, 25 Nov 2009 09:38:01 Z2009-11-25T09:38:02Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/75f73c7b-f2ac-4ee8-a820-b6b7c201eb8chttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/75f73c7b-f2ac-4ee8-a820-b6b7c201eb8cStephen J Wardhttp://social.msdn.microsoft.com/Profile/en-US/?user=Stephen%20J%20WardMVC and Self Tracking EntitiesWhen I'm using self tracking entities which are displayed in a form on an MVC view, the form values are posted to the Controller once updated. <br/> <br/> I would then need to re-create these entities from the posted form values. Wouldnt this lose tracking information needed for Optimistic locking?<br/> <br/> How can I work with self tracking entities in scenarios like this without storing the objects somewhere e.g. in the Session ?Tue, 24 Nov 2009 02:47:14 Z2009-11-27T04:52:01Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/83dcf7f5-d901-4e8f-b5e6-a8bc2006efb6http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/83dcf7f5-d901-4e8f-b5e6-a8bc2006efb6Calvin Lamhttp://social.msdn.microsoft.com/Profile/en-US/?user=Calvin%20LamSelf-Tracking Entities with Stored Procedure in Entity FrameworkDears,<br/><br/><br/>Technologies<br/>===============<br/>Technologies that I must use is WCF and Stored Procedures and Entity Framework to read data out, not for insert, update and delete<br/><br/><br/>Tasks<br/>===============<br/>Create a combo box with Category, when users change the selection on the combo box, a list of relative subcategories will be shown on a grid.<br/>User is able to create a new category directly and input some new subcategories as well.<br/><br/><br/>Databases<br/>===============<br/>Category<br/>{<br/>    CategoryID        INT<br/>    CategoryName   VARCHAR(50)<br/>}<br/><br/>SubCategory<br/>{<br/>    SubCategoryID        INT<br/>    SubCategoryCode    VARCHAR(20)<br/>    SubCategoryName   VARCAAR(50)<br/>}<br/><br/>Category   1 &lt;---&gt; N   SubCategory<br/><br/><br/>Stored Procedures<br/>===============<br/>GetAllCategories()  returns  [Category] Entity<br/><br/>Since I want to make those entities seperated from the DB but with Self Tracking functionalities for N-Tier application.<br/>I want to do something like shown as the following<br/><br/><br/>Implementation Class<br/>================<br/>using (InventoryEntities context = new InventoryEntities)<br/>{<br/>      Category[]  categoryList = context.GetAllCategories().ToArray();<br/>}<br/><br/>As this time, I can't use include since the return type for GetAllCategory() is a ObjectResult&lt;Category&gt; rather than ObjectSet&lt;Category&gt;<br/>I want to retrieve category with its subcategories at the same queries and the main point is using stored procedure.<br/><br/>This is a very simple scenario but I must deal with this situation successfully before I move further away.<br/><br/>If I want to return a self-tracking entities (For update purpose through WCF and N-Tiers architecture) with the following information<br/>with the specified technologies required, what can I do?<br/><br/>Category ID      Category Name     SubCategory ID     SubCategory Name<br/>     1                     Hardware<br/>                                                             1                       Server<br/>                                                             2                     Notebook<br/>                                                             3                       Monitor  <br/>    2                      Software<br/>                                                             4                       License<br/>    3                       Others<br/>                                                             5                      Service<br/><br/>Could anyone gives me a suggestion how can I achieve my purpose?<br/><br/>10 millions Thanks !!!!<br/><br/>Tue, 24 Nov 2009 07:35:26 Z2009-11-24T22:41:51Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/b295de9e-88b5-4471-8b00-a42047793646http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/b295de9e-88b5-4471-8b00-a42047793646SpinalTaphttp://social.msdn.microsoft.com/Profile/en-US/?user=SpinalTapModel First: How Do I Designate A Property (Column) To Have A UNIQUE INDEX?Hi, <br/><br/>I'm using EF 4 Beta 2 and Sql Server 2008. I'm doing model first design, and I'm wondering if/how I can designate a field to have a UNIQUE INDEX in the database? Can this be done? If not, is there a workaround? I can't I put indexes directly in Sql Server, cause every time I re-generate the database I'd lose them all.<br/><br/>Thanks!<br/><br/>SpinalThu, 19 Nov 2009 05:19:40 Z2009-11-24T22:14:59Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/781d7256-8226-4e56-a1aa-16ca33e1cbe7http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/781d7256-8226-4e56-a1aa-16ca33e1cbe7Tim Laverty- MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Tim%20Laverty-%20MSFTUsing Entity Framework 4 with SQL Server 2000 Databases<p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt">The Visual Studio 2010 IDE does not support connecting to SQL Server 2000, including not allowing connections from the ADO.NET Entity Framework designer.  However, the ADO.NET Entity Framework 4 runtime continues to offer support for running with SQL Server 2000 databases.  A number of people have asked what to do with existing ADO.NET Entity Framework models built against SQL Server 2000 when moving to Visual Studio 2010.  Following are a few development options and items of note:</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt"> </span></p> <p class=MsoListParagraph style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt"><span style="">-<span style="font:7pt &quot;Times New Roman&quot;">        </span></span></span><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt">The ADO .NET Entity Framework 4 runtime fully supports SQL Server 2000.  </span></p> <p class=MsoListParagraph style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt"><span style="">-<span style="font:7pt &quot;Times New Roman&quot;">        </span></span></span><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt">Apps you previously built on top of SQL Server 2000 will continue to function as-is when you move those apps to the ADO.NET Entity Framework 4 runtime.</span></p> <p class=MsoListParagraph style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt"><span style="">-<span style="font:7pt &quot;Times New Roman&quot;">        </span></span></span><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt">EdmGen.exe is a command line utility that can be used to create ADO.NET Entity Framework models.  It is still possible to use EdmGen.exe to generate ADO.NET Entity framework models for SQL Server 2000 databases.</span></p> <p class=MsoListParagraph style="text-indent:-0.25in;margin:0in 0in 0pt 0.5in"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt"><span style="">-<span style="font:7pt &quot;Times New Roman&quot;">        </span></span></span><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt">To use the Visual Studio 2010 tools with models built on top of SQL Server 2000 it’s possible to mirror your SQL Server 2000 schemas to SQL Server 2008 and SQL Server 2008 R2 instances for use with the designer tools.  </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt">Thanks, Tim Laverty</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-family:'Calibri','sans-serif';color:#1f497d;font-size:11pt">PM, Entity Framework</span></p>Tue, 24 Nov 2009 21:05:57 Z2009-11-24T22:28:22Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/d766924d-3a76-44c2-a0b3-bf12768a4d91http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/d766924d-3a76-44c2-a0b3-bf12768a4d91Lisa Tatumhttp://social.msdn.microsoft.com/Profile/en-US/?user=Lisa%20TatumSet referntial integrity like cascade delete integrated into visual studio model designer?Hello,<br/> <br/> with EF v1.0 I did this:<br/> <br/> that way all products got deleted when I deleted a category. How must I do this in VS 2010 beta 2? Also change in manually in xml code?? terrible...<br/> <p align=left><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&lt;</span> <span style="color:#a31515;font-size:x-small">Association</span> <span style="color:#0000ff;font-size:x-small"> </span> <span style="color:#ff0000;font-size:x-small">Name</span> <span style="color:#0000ff;font-size:x-small">=</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small">CProductCategory</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small">&gt;</span> </span></p> <p align=left><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">    &lt;</span> <span style="color:#a31515;font-size:x-small">End</span> <span style="color:#0000ff;font-size:x-small"> </span> <span style="color:#ff0000;font-size:x-small">Type</span> <span style="color:#0000ff;font-size:x-small">=</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small">Self.CProduct</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small"> </span> <span style="color:#ff0000;font-size:x-small">Multiplicity</span> <span style="color:#0000ff;font-size:x-small">=</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small">*</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small"> /&gt;</span> </span></p> <p align=left><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">    &lt;</span> <span style="color:#a31515;font-size:x-small">End</span> <span style="color:#0000ff;font-size:x-small"> </span> <span style="color:#ff0000;font-size:x-small">Type</span> <span style="color:#0000ff;font-size:x-small">=</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small">Self.CCategory</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small"> </span> <span style="color:#ff0000;font-size:x-small">Multiplicity</span> <span style="color:#0000ff;font-size:x-small">=</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small">0..1</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small">&gt;</span> </span></p> <p align=left><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">        &lt;</span> <span style="color:#a31515;font-size:x-small">OnDelete</span> <span style="color:#0000ff;font-size:x-small"> </span> <span style="color:#ff0000;font-size:x-small">Action</span> <span style="color:#0000ff;font-size:x-small">=</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small">Cascade</span> <span style="font-size:x-small">&quot;</span> <span style="color:#0000ff;font-size:x-small"> /&gt;</span> </span></p> <p align=left><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">    &lt;/</span> <span style="color:#a31515;font-size:x-small">End</span> <span style="color:#0000ff;font-size:x-small">&gt;</span> </span></p> <p align=left><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">&lt;/</span> <span style="color:#a31515;font-size:x-small">Association</span> <span style="color:#0000ff;font-size:x-small">&gt;</span> </span></p>Sat, 21 Nov 2009 11:31:17 Z2009-11-24T19:13:09Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/37fd6c91-e7af-4228-843e-3d8343929fc3http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/37fd6c91-e7af-4228-843e-3d8343929fc3SpinalTaphttp://social.msdn.microsoft.com/Profile/en-US/?user=SpinalTapSelf-Tracking Entities: Why is 'ChangeTrackingEnabled' = false By Default?<p>When using Self-tracking entities, I don't like having to call StartTracking() on all objects to have them start their tracking. I realize that after de-serializing calls this automatically, but I don't want to assume that these objects will only need to start tracking then, I might want to track entities on the server side as well. <br/><br/>Can I safely adjust the field on the ChangeTrackingEnabled field on the ObjectChangeTracker object to default to 'true'? After looking at the generated code, I don't think it will adversely affect anything, but not sure if I'm missing anything.<br/><br/>Any help is appreciated.<br/><br/><br/>Thanks,<br/>Spiny</p>Thu, 19 Nov 2009 19:35:32 Z2009-11-24T15:31:52Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/7b2e5387-eeba-4e25-9b97-747b3971c142http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/7b2e5387-eeba-4e25-9b97-747b3971c142Alexey Zakharovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Alexey%20ZakharovPOCO with EDMX : How map POCO entities from different namespaces in single EDMXHow can I map POCO entities from different namespaces in single EDMX?<br/> <br/> In my application I want to have one context, that work with all POCO entities which are located in different assemblies.Tue, 24 Nov 2009 07:35:00 Z2009-11-25T00:33:26Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/1bad6e95-ce6f-4c0d-aec6-0671dd9443a2http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/1bad6e95-ce6f-4c0d-aec6-0671dd9443a2Pedro M. A. Salgueirohttp://social.msdn.microsoft.com/Profile/en-US/?user=Pedro%20M.%20A.%20Salgueiro How to map a simple association and a composition in entity framework<div>We have the following scenarios:</div> <div><br/></div> <div>Associate a Invoice to a Customer POCO.</div> <div>If the associated customer does not exist an insert of the Invoice should fail. It should not attempt to insert the customer.</div> <div><br/></div> <div>Associate a Invoice to InvoiceLines POCOs.</div> <div>All InvoiceLines in the collection should be inserted.</div> <div><br/></div> <div>Talking in terms of UML notation what is the diference in CSDL and MSL of Aggregation and Composition?</div> <div><br/></div> <div>Thank you,</div> <div>Pedro</div><hr class="sig">Pedro SalgueiroFri, 13 Nov 2009 16:11:45 Z2009-11-24T12:19:48Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/34270ef5-2fd5-43ff-8ddf-912a2a572869http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/34270ef5-2fd5-43ff-8ddf-912a2a572869Stephen J Wardhttp://social.msdn.microsoft.com/Profile/en-US/?user=Stephen%20J%20WardSQL timestamp in VB POCO object<p>I'm using POCOs with the latest version of EF 4.0 and have a timestamp field on my SQL Server 2008 db for handling optimistic concurrency.</p> <p>The designer has created a mapping for the field with as an entity type of Binary. How should this be represented in my VB POCO as EDM.Binary is not available there? When I have the field as a Byte array, I get the error:</p> <p>The type 'Edm.Binary' of the member 'RowVersionNr' in the conceptual side type 'SchoolModel.Course' does not match with the type 'System.Byte' of the member 'RowVersionNr' on the object side type 'EFLibrary.Course'.</p>Tue, 24 Nov 2009 02:49:31 Z2009-11-27T04:51:21Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/f8ffba41-efc0-4759-8929-f8c9adc909e6http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/f8ffba41-efc0-4759-8929-f8c9adc909e6SpinalTaphttp://social.msdn.microsoft.com/Profile/en-US/?user=SpinalTapCustom Code Generation Strategy?Hi,<br/>I created a custom Database Generation Workflow for database code generation and it works great. <br/><br/>(For anyone interested, I followed the lead of the 'dev guy's 'D3' app:<br/>(<a href="http://blogs.msdn.com/dsimmons/archive/2009/06/30/d3-building-great-software-is-a-battle-don-t-leave-any-assets-on-the-sidelines.aspx">http://blogs.msdn.com/dsimmons/archive/2009/06/30/d3-building-great-software-is-a-battle-don-t-leave-any-assets-on-the-sidelines.aspx</a>)<br/><br/>I would like to do the same thing for the Code generation - is there such a thing? I know i can create T4 scripts and attach them to the edmx file, but I'd like to go one further and have actual C# code triggered, primarily to do more in-depth integration with VS, such as automatic check-outs, etc. I see this can be done on the db gen side with workflow activities, but does the  code generation side of things have the same capability? Or am I best off just sticking to the existing database generation workflow for this kind of thing?<br/><br/>Thanks!<br/><br/>Spinal<br/><br/><br/>Mon, 23 Nov 2009 18:41:36 Z2009-11-24T07:21:02Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/87ab6120-9582-4aeb-a6bd-6380ba6731dahttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/87ab6120-9582-4aeb-a6bd-6380ba6731dapaulobragahttp://social.msdn.microsoft.com/Profile/en-US/?user=paulobragaCreating/Updating entities with complex relationshipsHi,<br/><br/>Having migrated our projects to VS 2010 Beta2, we are trying the EF 4.0 as orm for the DAL, and have the following scenario:<br/>Based on our own DSL, we are generating, besides other components, the following elements relevants for the question:<br/>1. Database scripts.<br/>2. Business Entities (POCOs). For this purpose, let's assume as simple classes with getters and setters.<br/>3. EF files (ssdl, csdl, and msl).<br/>4. Classes that inherit from from ObjectContext, storing ObjectSet's for each entities.<br/><br/>We can successfully create and update simple entites with the following code (example for a <em>Product</em> object): <pre lang="x-c#"> public void CreateProduct (Product instance) { products.Attach(instance); ObjectStateManager.ChangeObjectState(instance, EntityState.Added); products.AddObject(instance); this.SaveChanges(); } public void UpdateProduct (Product instance) { products.Attach(instance); ObjectStateManager.ChangeObjectState(instance, EntityState.Modified); products.ApplyCurrentValues(instance); this.SaveChanges(); }</pre> In this case, <em>products </em>is of type <em>ObjectSet&lt;Product&gt;.<br/></em><br/>The problems start when the objects are more complex. For example, in a master-detail scenario (ex: Order-OrderDetails), we are getting the following error:<br/><br/><em>&quot;An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key</em>&quot;.<br/>It occurs in the line of the Attach method, as the example above (in that case <em>invoices.Attach(instance); </em>)<br/><br/>As we are new with EF, we are not really sure about if this is the better way to implement these Create/Update methods. Also, and as I could understand, it seems to be something related with self-tracking entities, and have read about the Entity Framework Feature which is still not shipped for VS 2010 Beta2.<br/><br/>So, the question is, is this the right way to do the job and what is missing for these scenarios? Does the EF Feature CTP effectively the best way to handle this?<br/><br/>Many thanks in advance.<br/><hr class="sig">pauloThu, 29 Oct 2009 23:36:56 Z2009-11-24T09:18:41Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/b25ceead-6043-4b3c-86fe-7c77d7971b62http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/b25ceead-6043-4b3c-86fe-7c77d7971b62majhulhttp://social.msdn.microsoft.com/Profile/en-US/?user=majhulstored procedure- multiple return typesHi,<br/><br/>I am trying to migrate my code to EF4 and I  need help using stored proc that returns multiple result types.<br/>In linq to sql i managed doing it by using &quot;<span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">IMultipleResults</span></span> &quot; interface and &quot;<span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">ResultType&quot; attribute.<br/>How can I use sp with multiple results type in EF4?<br/><br/> <pre lang="x-c#">[Function(Name = &quot;dbo.P_USR_UserSummeryDetails&quot;)] [ResultType(typeof(User))] [ResultType(typeof(Operation))] [ResultType(typeof(OrganizationUnit))] [ResultType(typeof(OrganizationUnit))] [ResultType(typeof(Role))] [ResultType(typeof(User))] [ResultType(typeof(User))] public IMultipleResults GetUserSummeryDetails(int userID, string loginName, int fillMode) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), userID, loginName, fillMode); return ((IMultipleResults)(result.ReturnValue)); }</pre> <br/></span></span>Wed, 18 Nov 2009 11:49:00 Z2009-11-23T22:07:11Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/02b203b7-9c78-4b0f-a2bd-1ffb6c1e2dbehttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/02b203b7-9c78-4b0f-a2bd-1ffb6c1e2dbezeeshan hiranihttp://social.msdn.microsoft.com/Profile/en-US/?user=zeeshan%20hiraniDetectChanges not required when you you call objectset.addobjectI am using plain POCO with no proxies. <div><br/></div> <div> <div>var db = new CustomContext();</div> <div>var speaker = new Speaker { Name = &quot;John&quot; };</div> <div>var talk1 = new Talk { Title = &quot;New EF4 features&quot; };</div> <div>speaker.Talks = new List&lt;Talk&gt;() { talk1 };</div> <div>//object graph not synced</div> <div>Console.WriteLine(&quot;talk1.Sepaker is null {0}&quot;,talk1.Speakers == null);</div> <div>db.Speakers.AddObject(speaker);</div> <div><br/></div> <div>//object graph synced</div> <div>Console.WriteLine(&quot;talk1.Sepaker is not null {0}&quot;, talk1.Speakers.Count() &gt; 0);</div> <div><br/></div> <div>As soon as i add the speak to the objectset of speakers both sides of the graph is synced and changes on the object are noticed by the statemanager. I thought DetectChanges is an expensive operation which is only called when you call SaveChanges or when you explicitly call detect changes. atleast that's what the blog says.</div> <div><br/></div> <div><span style="font-size:12px;line-height:18px">Because <strong style="padding:0px;margin:0px">DetectChanges</strong> is potentially expensive, it isn’t called explicitly during the other APIs on ObjectContext that rely on the state manager being in sync with the object graph. As a result, you have to call <strong style="padding:0px;margin:0px">DetectChanges</strong> whenever you are performing state dependent operations on the context.</span></div> <div><span style="font-size:small"><span style="font-size:12px;line-height:18px"><br/></span></span></div> <div><span style="font-size:small"><span style="font-size:12px;line-height:18px">Zeeshan Hirani</span></span></div> </div>Sat, 21 Nov 2009 19:14:11 Z2009-11-24T22:42:53Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a70e79d9-f9aa-42e4-9396-c11fd22141fbhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a70e79d9-f9aa-42e4-9396-c11fd22141fbAlexey Zakharovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Alexey%20ZakharovHow to declare many to many relationship in code only scenarioHow to declare many to many relationship in code only scenario?Sat, 21 Nov 2009 06:14:09 Z2009-11-23T05:14:41Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/ba25138d-714e-4055-a53d-aa499e67045ehttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/ba25138d-714e-4055-a53d-aa499e67045ecaptBielehttp://social.msdn.microsoft.com/Profile/en-US/?user=captBieleHow to get a bindable collection from EF4?I'm experimenting with databinding using WPF and EF4. <div><br/></div> <div>I generated my model first, which includes a Product entity.</div> <div><br/></div> <div>I'd like to have a databound-property that holds a collection of product entities, and supports change notification (when an item is added/deleted)</div> <div><br/></div> <div>Currently I'm converting the resulting ObjectSet&lt;Product&gt; into an ObservableCollection, but there must be an easier way. Now, I have to synchronize two collections.</div> <div><br/></div> <div>Any help on this is appreciated!</div>Sun, 22 Nov 2009 20:56:21 Z2009-11-23T04:58:14Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/c3729a64-d20a-4ba3-bc57-fbd5fa735125http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/c3729a64-d20a-4ba3-bc57-fbd5fa735125SpinalTaphttp://social.msdn.microsoft.com/Profile/en-US/?user=SpinalTapObjectStateEntry Not Showing Correct State During SavingChanges Event<p>Hi,<br/>I'm using Self-tracking entities in EF4. I have a 'LastModified' DateTime field in all my entities that I want to update on all inserts/updates,<br/>so I've implemented an event handler for my ObjectContext's 'SavingChanges' event. In it, I inspect all the ObjectStateEntries on the context's ObjectStateManager, as follows:<br/><br/>private void context_SavingChanges(object sender, EventArgs e)<br/>{<br/>    ObjectContext context = sender as ObjectContext;<br/>    if (context != null) {<br/> foreach (ObjectStateEntry entry in context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified))   {<br/>   . . .<br/> <br/> }<br/>}<br/><br/>It works fine for new objects that I spin up and insert, but when updating a loaded entity, the ObjectStateEntry.State is never 'Modified', it's always 'Unchanged', even though the entity that it's referencing is 'Modified' (the entity's StateTracker, that is). This is not the case for inserts, only updates. I could start checking State of the entities themselves, instead of the ObjectStateEntry, but I have the feeling I'm doing something wrong to cause this issue. My calling code is simply:<br/><br/>using (var context = new MyContext()) {</p> <p> var results = from f in context.Foo<br/>        where f.Id == 123<br/>        select f;<br/> Foo foo = results.SingleOrDefault&lt;Foo&gt;();</p> <p> foo.StartTracking();<br/> foo.Name = &quot;some string&quot;;</p> <p> context.Foo.ApplyChanges(foo);<br/> context.SaveChanges();<br/>}<br/><br/>Any ideas are much appreciated!<br/><br/><br/>Thanks,<br/>Spinal</p>Thu, 19 Nov 2009 19:15:56 Z2009-11-23T04:16:10Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a0936d60-5524-4eb7-af8b-bd78cbf22f55http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a0936d60-5524-4eb7-af8b-bd78cbf22f55zeeshan hiranihttp://social.msdn.microsoft.com/Profile/en-US/?user=zeeshan%20hiraniIs detectchanges called before savingchanges or after?If i have business logic applied in saving changes event on pure poco object, those get unnoticed. Apparently Ef calls detect changes after SavingChanges so some of my business logic gets skipped for instance in the code below, I dont get anything for added talks state entries cuz snapt shot happens after saving changes. What are the recommendations and also what happens if i override SaveChanges method, do I take the responsibility of invoking detectchanges then? <div><br/></div> <div>I think diego mentioned in ado.net blog comment that DetectChanges is called before SavingChanges event fire which i don't understand. diego can u pls explain?</div> <div><br/></div> <div><span style="line-height:18px">&quot;Regarding your second point, in SaveChanges, by default, DetectChanges is invoked right before raising the SavingChanges event, so you shouldn't need to call DetectChanges yourself.&quot;</span><br/> <div><br/></div> <div> <div>speaker.Talks.Add(new Talk { Title = &quot;jquery intro&quot; });</div> <div>            db.SaveChanges();</div> <div><br/></div> <div> <div> void CustomContext_SavingChanges(object sender, EventArgs e)</div> <div> {</div> <div>     var addedtalks = this.ObjectStateManager.GetObjectStateEntries(EntityState.Added)</div> <div>                     .Where(en =&gt; en.Entity is Talk)</div> <div>                     .Select(en =&gt; en.Entity as Talk);</div> <div>     foreach (var talk in addedtalks)</div> <div>     {</div> <div>         talk.CreateDate = DateTime.Now;</div> <div>     }</div> <div> }</div> <div><br/></div> <div>Zeeshan Hirani</div> </div> </div> </div>Sat, 21 Nov 2009 20:03:36 Z2009-11-22T03:34:06Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/614ba911-5ffc-4d00-b4d3-fa06932ac8f3http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/614ba911-5ffc-4d00-b4d3-fa06932ac8f3Michael_R.http://social.msdn.microsoft.com/Profile/en-US/?user=Michael_R.ADO.Net EF V4 Beta 2 - Limitation or Mistake? - PROC Mapping for Insert/Update/Delete - More than 1 return parameter<p>I'm concerned I've hit a limitation in the ADO.Net EF 4 (beta 2), but I'm not sure if that's the case, or I'm just doing something wrong. I have an entity that includes an identity field and a computed column. The insert PROC needs to return 2 values to update the entity and one of those values is used is an Association. The update PROC needs to return 1 value and it's also the one used in a mapping. In both cases, that value also needs to be an input to the PROC (for business logic handles in sql that can be seen in the proc below).  Can someone tell me what I'm doing wrong with my ModificationFunctionMapping, or if I've hit a limitation in the EF. In the designer, I get the impression I can't have 2 ResultBindings, and even then, it seems I can't use them because the field is used in a NavigationProperty.</p> <p>Thanks in advance for any/all help. This is a show-stopper for this project since I must rely on views/procs for security reasons (until/unless transparent row-level security is available to me in this scenario with SQL 2008 and the EF).</p> <p><br/><strong>The PROC Definition:</strong></p> <pre lang=x-sql>ALTER PROC [appSec].[SubjectTreeNode_insert] @ID int OUTPUT, @SubjectTree int, @pRef int, @Title varchar(100), @Description varchar(250), @OrderWeight int, @ExpandState bit, @pRef2 int OUTPUT AS BEGIN INSERT INTO dbo.SubjectTreeNode ( [SubjectTree], [pRef], [Title], [Description], [OrderWeight], [ExpandState] ) VALUES ( @SubjectTree, CASE WHEN @pRef2=@pRef THEN @pRef2 WHEN @pRef2 IS NOT NULL THEN @pRef2 ELSE @pRef END, @Title, @Description, @OrderWeight, @ExpandState ) SELECT @ID=ID, @pRef2=pRef2 FROM dbo.SubjectTreeNode WHERE ID = SCOPE_IDENTITY() END</pre> <p><br/><strong>The EntityType:</strong></p> <pre lang=x-xml> &lt;EntityType Name=&quot;SubjectTreeNode_appSec&quot;&gt; &lt;Key&gt; &lt;PropertyRef Name=&quot;ID&quot; /&gt; &lt;/Key&gt; &lt;Property Type=&quot;Int32&quot; Name=&quot;ID&quot; Nullable=&quot;false&quot; /&gt; &lt;Property Type=&quot;Int32&quot; Name=&quot;pRef&quot; Nullable=&quot;false&quot; /&gt; &lt;Property Type=&quot;String&quot; Name=&quot;Title&quot; Nullable=&quot;false&quot; MaxLength=&quot;100&quot; /&gt; &lt;Property Type=&quot;String&quot; Name=&quot;Description&quot; Nullable=&quot;true&quot; MaxLength=&quot;250&quot; /&gt; &lt;Property Type=&quot;Int16&quot; Name=&quot;OrderWeight&quot; Nullable=&quot;false&quot; /&gt; &lt;Property Type=&quot;Boolean&quot; Name=&quot;ExpandState&quot; Nullable=&quot;true&quot; /&gt; &lt;Property Type=&quot;Int16&quot; Name=&quot;IsTopLevel&quot; Nullable=&quot;true&quot; a:StoreGeneratedPattern=&quot;Computed&quot; xmlns:a=&quot;http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator&quot; /&gt; &lt;NavigationProperty Name=&quot;SubjectTree_appSec&quot; Relationship=&quot;edmTESTSCORING2.SubjectTree_appSecSubjectTreeNode_appSec&quot; FromRole=&quot;SubjectTreeNode_appSec&quot; ToRole=&quot;SubjectTree_appSec&quot; /&gt; &lt;NavigationProperty Name=&quot;SubjectTreeNodeAssoc_appSec&quot; Relationship=&quot;edmTESTSCORING2.SubjectTreeNode_appSecSubjectTreeNodeAssoc_appSec&quot; FromRole=&quot;SubjectTreeNode_appSec&quot; ToRole=&quot;SubjectTreeNodeAssoc_appSec&quot; /&gt; &lt;NavigationProperty Name=&quot;SubjectTreeNode_appSec_children&quot; Relationship=&quot;edmTESTSCORING2.SubjectTreeNode_appSecSubjectTreeNode_appSec&quot; FromRole=&quot;SubjectTreeNode_appSec_parent&quot; ToRole=&quot;SubjectTreeNode_appSec_children&quot; /&gt; &lt;NavigationProperty Name=&quot;SubjectTreeNode_appSec_parent&quot; Relationship=&quot;edmTESTSCORING2.SubjectTreeNode_appSecSubjectTreeNode_appSec&quot; FromRole=&quot;SubjectTreeNode_appSec_children&quot; ToRole=&quot;SubjectTreeNode_appSec_parent&quot; /&gt; &lt;/EntityType&gt;</pre> <p>       <br/><strong>The EntitySet:</strong></p> <pre lang=x-xml> &lt;EntitySet Name=&quot;SubjectTreeNode_appSec&quot; EntityType=&quot;edmTESTSCORING2.Store.SubjectTreeNode&quot; store:Type=&quot;Views&quot; store:Schema=&quot;appSec&quot; store:Name=&quot;SubjectTreeNode_appSec&quot;&gt; &lt;DefiningQuery&gt; SELECT TOP 100 PERCENT STN.[ID], STN.[SubjectTree], STN.[pRef], STN.[Title], STN.[Description], STN.[OrderWeight], STN.[ExpandState], STN.[IsTopLevel], STN.[pRef2] FROM appSec.SubjectTreeNode as STN &lt;/DefiningQuery&gt; &lt;/EntitySet&gt;</pre> <p><br/><strong>The Association:</strong></p> <pre lang=x-xml> &lt;Association Name=&quot;SubjectTreeNode_appSecSubjectTreeNode_appSec&quot;&gt; &lt;End Type=&quot;edmTESTSCORING2.SubjectTreeNode_appSec&quot; Role=&quot;SubjectTreeNode_appSec_parent&quot; Multiplicity=&quot;0..1&quot; /&gt; &lt;End Type=&quot;edmTESTSCORING2.SubjectTreeNode_appSec&quot; Role=&quot;SubjectTreeNode_appSec_children&quot; Multiplicity=&quot;*&quot; /&gt; &lt;/Association&gt;</pre> <p>                <br/><strong>The AssociationSet:</strong></p> <pre lang=x-xml> &lt;AssociationSet Name=&quot;SubjectTreeNode_appSecSubjectTreeNodeAssoc_appSec&quot; Association=&quot;edmTESTSCORING2.SubjectTreeNode_appSecSubjectTreeNodeAssoc_appSec&quot;&gt; &lt;End Role=&quot;SubjectTreeNode_appSec&quot; EntitySet=&quot;SubjectTreeNode_appSecs&quot; /&gt; &lt;End Role=&quot;SubjectTreeNodeAssoc_appSec&quot; EntitySet=&quot;SubjectTreeNodeAssocs_appSec&quot; /&gt; &lt;/AssociationSet&gt;</pre> <p><br/><strong>The AssociationSetMapping:</strong></p> <pre lang=x-xml> &lt;AssociationSetMapping Name=&quot;SubjectTreeNode_appSecSubjectTreeNode_appSec&quot; TypeName=&quot;edmTESTSCORING2.SubjectTreeNode_appSecSubjectTreeNode_appSec&quot; StoreEntitySet=&quot;SubjectTreeNode_appSec&quot;&gt; &lt;EndProperty Name=&quot;SubjectTreeNode_appSec_children&quot;&gt; &lt;ScalarProperty Name=&quot;ID&quot; ColumnName=&quot;ID&quot; /&gt; &lt;/EndProperty&gt; &lt;EndProperty Name=&quot;SubjectTreeNode_appSec_parent&quot;&gt; &lt;ScalarProperty Name=&quot;ID&quot; ColumnName=&quot;pRef2&quot; /&gt; &lt;/EndProperty&gt; &lt;Condition ColumnName=&quot;pRef2&quot; IsNull=&quot;false&quot; /&gt; &lt;/AssociationSetMapping&gt;</pre> <p><br/>          <br/><strong>The EntitySetMapping (and the problem):</strong></p> <pre lang=x-xml> &lt;EntitySetMapping Name=&quot;SubjectTreeNode_appSecs&quot;&gt; &lt;EntityTypeMapping TypeName=&quot;IsTypeOf(edmTESTSCORING2.SubjectTreeNode_appSec)&quot;&gt; &lt;MappingFragment StoreEntitySet=&quot;SubjectTreeNode_appSec&quot;&gt; &lt;ScalarProperty Name=&quot;IsTopLevel&quot; ColumnName=&quot;IsTopLevel&quot; /&gt; &lt;ScalarProperty Name=&quot;ExpandState&quot; ColumnName=&quot;ExpandState&quot; /&gt; &lt;ScalarProperty Name=&quot;OrderWeight&quot; ColumnName=&quot;OrderWeight&quot; /&gt; &lt;ScalarProperty Name=&quot;Description&quot; ColumnName=&quot;Description&quot; /&gt; &lt;ScalarProperty Name=&quot;Title&quot; ColumnName=&quot;Title&quot; /&gt; &lt;ScalarProperty Name=&quot;pRef&quot; ColumnName=&quot;pRef&quot; /&gt; &lt;ScalarProperty Name=&quot;ID&quot; ColumnName=&quot;ID&quot; /&gt; &lt;/MappingFragment&gt; &lt;/EntityTypeMapping&gt; &lt;EntityTypeMapping TypeName=&quot;edmTESTSCORING2.SubjectTreeNode_appSec&quot;&gt; &lt;ModificationFunctionMapping&gt; &lt;InsertFunction FunctionName=&quot;edmTESTSCORING2.Store.SubjectTreeNode_insert&quot; RowsAffectedParameter=&quot;ID&quot;&gt; &lt;AssociationEnd AssociationSet=&quot;SubjectTree_appSecSubjectTreeNode_appSec&quot; From=&quot;SubjectTreeNode_appSec&quot; To=&quot;SubjectTree_appSec&quot;&gt; &lt;ScalarProperty Name=&quot;ID&quot; ParameterName=&quot;SubjectTree&quot; /&gt;&lt;/AssociationEnd&gt; &lt;AssociationEnd AssociationSet=&quot;SubjectTreeNode_appSecSubjectTreeNode_appSec&quot; From=&quot;SubjectTreeNode_appSec_children&quot; To=&quot;SubjectTreeNode_appSec_parent&quot;&gt; &lt;ScalarProperty Name=&quot;ID&quot; ParameterName=&quot;pRef2&quot; /&gt;&lt;/AssociationEnd&gt; &lt;ScalarProperty Name=&quot;ID&quot; ParameterName=&quot;ID&quot; /&gt; &lt;ScalarProperty Name=&quot;ExpandState&quot; ParameterName=&quot;ExpandState&quot; /&gt; &lt;ScalarProperty Name=&quot;OrderWeight&quot; ParameterName=&quot;OrderWeight&quot; /&gt; &lt;ScalarProperty Name=&quot;Description&quot; ParameterName=&quot;Description&quot; /&gt; &lt;ScalarProperty Name=&quot;Title&quot; ParameterName=&quot;Title&quot; /&gt; &lt;ScalarProperty Name=&quot;pRef&quot; ParameterName=&quot;pRef&quot; /&gt; &lt;ResultBinding Name=&quot;ID&quot; ColumnName=&quot;ID&quot; /&gt; &lt;/InsertFunction&gt; &lt;UpdateFunction FunctionName=&quot;edmTESTSCORING2.Store.SubjectTreeNode_update&quot; RowsAffectedParameter=&quot;pRef2&quot;&gt; &lt;AssociationEnd AssociationSet=&quot;SubjectTreeNode_appSecSubjectTreeNode_appSec&quot; From=&quot;SubjectTreeNode_appSec_children&quot; To=&quot;SubjectTreeNode_appSec_parent&quot;&gt; &lt;ScalarProperty Name=&quot;ID&quot; ParameterName=&quot;pRef2&quot; Version=&quot;Current&quot; /&gt;&lt;/AssociationEnd&gt; &lt;AssociationEnd AssociationSet=&quot;SubjectTree_appSecSubjectTreeNode_appSec&quot; From=&quot;SubjectTreeNode_appSec&quot; To=&quot;SubjectTree_appSec&quot;&gt; &lt;ScalarProperty Name=&quot;ID&quot; ParameterName=&quot;SubjectTree&quot; Version=&quot;Current&quot; /&gt;&lt;/AssociationEnd&gt; &lt;ScalarProperty Name=&quot;ExpandState&quot; ParameterName=&quot;ExpandState&quot; Version=&quot;Current&quot; /&gt; &lt;ScalarProperty Name=&quot;OrderWeight&quot; ParameterName=&quot;OrderWeight&quot; Version=&quot;Current&quot; /&gt; &lt;ScalarProperty Name=&quot;Description&quot; ParameterName=&quot;Description&quot; Version=&quot;Current&quot; /&gt; &lt;ScalarProperty Name=&quot;Title&quot; ParameterName=&quot;Title&quot; Version=&quot;Current&quot; /&gt; &lt;ScalarProperty Name=&quot;pRef&quot; ParameterName=&quot;pRef&quot; Version=&quot;Current&quot; /&gt; &lt;ScalarProperty Name=&quot;ID&quot; ParameterName=&quot;ID&quot; Version=&quot;Current&quot; /&gt; &lt;/UpdateFunction&gt; &lt;DeleteFunction FunctionName=&quot;edmTESTSCORING2.Store.SubjectTreeNode_delete&quot;&gt; &lt;ScalarProperty Name=&quot;ID&quot; ParameterName=&quot;ID&quot; /&gt;&lt;/DeleteFunction&gt;&lt;/ModificationFunctionMapping&gt;&lt;/EntityTypeMapping&gt; &lt;/EntitySetMapping&gt;</pre>Fri, 20 Nov 2009 11:45:33 Z2009-11-22T03:46:27Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/1e08f34c-5c58-4059-8ed8-94afec98956chttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/1e08f34c-5c58-4059-8ed8-94afec98956cN_CSU-Longhttp://social.msdn.microsoft.com/Profile/en-US/?user=N_CSU-LongThe logc.dll being used by another processHi,<br /> Well I dont know it sounds really easy but I am not able to find the solution for it. The Problem is <br /> <br /> &quot;&nbsp; Unable to copy file &quot;C:\skm\Ptx\Business\Logic\bin\Debug\Logic.dll&quot; to &quot;bin\Debug\Logic.dll&quot;. The process cannot access the file 'bin\Debug\Logic.dll' because it is being used by another process. &quot;<br /> <br /> Here is my code :<br /> public class Logic <br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static Logic()<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void Init()<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (myModel != null)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myModel = new Data.Model.GlobalEntities();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myModel.ContextOptions.DeferredLoadingEnabled = true;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Logic.ProjectDS.ProjectEntities DSctx;<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static IStudyCaseLogic studycaseLogic = new StudyCaseLogic();<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static bool DataServices = false;<br /> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Model.GlobalEntities myModel;<br /> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void Dispose()<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (myModel == null)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myModel.Dispose();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myModel = null;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> <br /> So this code is working good first time. Then i change some just like press enter ramdomly and save the logic file build it again and it shows the error.<br /> Some how it is not leaving the resources it aquire.<br /> <br /> Any Help appreciated,<br /> NFri, 02 Oct 2009 15:21:17 Z2009-11-21T13:47:11Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/03cfa372-501d-47dd-946e-ac74e5337c9chttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/03cfa372-501d-47dd-946e-ac74e5337c9cMBursillhttp://social.msdn.microsoft.com/Profile/en-US/?user=MBursillMapping a foreign key participating in multiple relationshipsI have a large database with a subset of five tables described here:<br/> <br/> <a title="Tables Diagram" href="http://www.senselessdestruction.com/AssociationProblem.jpg" title="Tables Diagram">http://www.senselessdestruction.com/AssociationProblem.jpg</a> <br/> <br/> When creating an entity model based on those tables I get the error:<br/> <br/> Foreign key constraint 'FK_UserContractCompanies_TimesheetContractEntries' has been omitted from the storage model. Column 'CompanyId' of table 'SMSModel.Store.UserContractCompanies' is a foreign key participating in multiple relationships. A one-to-one Entity Model will not validate since data inconsistency is possible.<br/> <br/> The intended business logic is to have a subset of users as contract users. A contract user arrives at the workplace, can sign in (an entry is made in the TimesheetEntries table), work for X hours and then sign out. For any user that is a contract user, the TimesheetContractEntries table exists to record their times broken into two records. The first record would be start and end times showing the first 8.5 hours of work, without a related ContractCompanyId, and the second record would be the remaining time with a related ContractCompanyId.<br/> <br/> I'm using VS 2010 Beta 2, and have tried including foreign key columns in the model. Is the schema of my database flawed or is there anyway to overcome this limitation in the EF?<br/> <br/> -Mike.Sun, 15 Nov 2009 19:23:09 Z2009-11-21T08:21:08Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/24bc0064-dff2-4d54-b75d-2eb2996759b4http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/24bc0064-dff2-4d54-b75d-2eb2996759b4SpinalTaphttp://social.msdn.microsoft.com/Profile/en-US/?user=SpinalTapShould Disconnected / Self-Tracking Entities Fire the OptimisticConcurrencyException?I'm running concurrency tests with EF4 B2 Self-tracking entities and I can't get EF to throw the OptimisticConcurrencyException, even when I debug and inpect and see that the version about to be saved is different from the saved version. Is there any issue with self-tracking entities in this regard?<br/><br/><br/>Thanks!Fri, 20 Nov 2009 20:54:38 Z2009-11-21T07:16:40Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/e10ef137-aa9d-4b4f-bf1b-0002c99d8303http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/e10ef137-aa9d-4b4f-bf1b-0002c99d8303Alexey Zakharovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Alexey%20ZakharovModel first development with POCOHi,<br/> <br/> I've just watched PDC 2009 Talk about EF.<br/> <br/> You've showed how generated classes could be replaced with poco. <br/> <br/> If I will change my POCO classes. How could i reflect those changes to database and mapping xml files.<br/> <br/> Best regards,<br/> Alexey Zakharov.Fri, 20 Nov 2009 20:14:22 Z2009-11-23T03:41:50Zhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/4d6fd8a8-8fe8-43f8-8a49-a825a7ec9c9dhttp://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/4d6fd8a8-8fe8-43f8-8a49-a825a7ec9c9dBeatenhttp://social.msdn.microsoft.com/Profile/en-US/?user=BeatenHow To Use POCO Support in EF 4 To Modify a Query (VB)?I need to refine all EF queries to apply a business rule to one of the properties. <div><br/></div> <div>Can this be done using EF4's POCO support? Could someone show me some code that demonstrates this (VB preferred)?</div> <div><br/></div> <div>Thks</div> <div><br/></div> <div>S</div> <div><br/></div>Fri, 20 Nov 2009 03:27:32 Z2009-11-20T19:19:08Z