<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - Question about EF</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - Question about EF</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Wed, 22 May 2013 18:23:16 GMT</pubDate>
	<lastBuildDate>Wed, 22 May 2013 18:23:16 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>7</c9:totalResults>
	<c9:pageCount>-7</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - Question about EF</title>
		<description><![CDATA[<p>Maybe I'm missing something here, but is there any way to update the primary key of an entity?</p><p>I know that PKs should be immutable, but I'm working with an existing database where some of the tables are set up with PKs that routinely change. If EF doesn't support this, then EF is pretty much a non-starter.</p><p>Here's my test code. The database table is a made up one for testing EF.<pre class="brush: vb">
Module Module1

    Sub Main()

        Console.Out.WriteLine(&quot;Loading...&quot;)
        Dim p As New Paradev()
        Dim c = Aggregate r In p.CustomerOrders Into Count()

        Console.Out.WriteLine(&quot;Count is {0}&quot;, c)

        Dim first = p.CustomerOrders.First()
        first.Amount = 12345
        p.SaveChanges()

        Console.In.ReadLine()
    End Sub

End Module

Public Class CustomerOrder
    Public Property Name As String
    Public Property OrderDate As Date?
    Public Property Amount As Decimal?
End Class

Public Class Paradev
    Inherits DbContext

    Public Property CustomerOrders As DbSet(Of CustomerOrder)

    Protected Overrides Sub OnModelCreating(modelBuilder As System.Data.Entity.DbModelBuilder)
        modelBuilder.Entity(Of CustomerOrder).HasKey(Function(t) New With {t.Name, t.OrderDate, t.Amount})
        modelBuilder.Entity(Of CustomerOrder).Property(Function(t) t.Name).HasColumnName(&quot;NAME&quot;)
        modelBuilder.Entity(Of CustomerOrder).Property(Function(t) t.Amount).HasColumnName(&quot;AMT&quot;)
        modelBuilder.Entity(Of CustomerOrder).Property(Function(t) t.OrderDate).HasColumnName(&quot;DT&quot;)
        modelBuilder.Entity(Of CustomerOrder)().ToTable(&quot;CUSTOMER_ORDERS&quot;, &quot;SSP01953&quot;)
    End Sub

End Class</pre></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Question-about-EF/ad24da3709c04af78207a1090121be2d#ad24da3709c04af78207a1090121be2d</link>
		<pubDate>Wed, 14 Nov 2012 17:34:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Question-about-EF/ad24da3709c04af78207a1090121be2d#ad24da3709c04af78207a1090121be2d</guid>
		<dc:creator>Scott</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/spivonious/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Question about EF</title>
		<description><![CDATA[<p>Why not have a proxy database that EF can rely on PKs?</p><p>You could map from the proxy database to the 'real' database (via whatever PK&nbsp;vodoo you doo).</p><p>Or perhaps have surrogate keys in addition to PKs-that-EF-can-rely-upon for your strange usage...</p><p>'Routinely changing PKs'... I'm not sure I want to know why... sounds quite desperate.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Question-about-EF/2c56a62a4f864af0a3fca109012c552d#2c56a62a4f864af0a3fca109012c552d</link>
		<pubDate>Wed, 14 Nov 2012 18:13:28 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Question-about-EF/2c56a62a4f864af0a3fca109012c552d#2c56a62a4f864af0a3fca109012c552d</guid>
		<dc:creator>JohnAskew</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/JohnAskew/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Question about EF</title>
		<description><![CDATA[<p>@<a href="/Forums/TechOff/Question-about-EF#c2c56a62a4f864af0a3fca109012c552d">JohnAskew</a>: Like I said, it's an existing database with other applications reading it, so updating the key structure isn't a real option.</p><p>I was just surprised at this limitation of EF, since every database I've ever used lets you update the PK column. I wonder what the reasoning is behind this decision. Does EF not&nbsp;track original values like ADO.NET DataColumns do?</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Question-about-EF/e399e03c4f2d49fd982ba10a00efaf94#e399e03c4f2d49fd982ba10a00efaf94</link>
		<pubDate>Thu, 15 Nov 2012 14:32:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Question-about-EF/e399e03c4f2d49fd982ba10a00efaf94#e399e03c4f2d49fd982ba10a00efaf94</guid>
		<dc:creator>Scott</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/spivonious/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Question about EF</title>
		<description><![CDATA[<p></p><blockquote><div class="quoteText"><p></p><p><a class="permalink" title="Post Permalink" href="/Forums/TechOff/Question-about-EF/e399e03c4f2d49fd982ba10a00efaf94">1 hour&nbsp;ago</a>, <a href="/Niners/spivonious">spivonious</a> wrote</p><p>@<a href="/Forums/TechOff/Question-about-EF#c2c56a62a4f864af0a3fca109012c552d">JohnAskew</a>: Like I said, it's an existing database with other applications reading it, so updating the key structure isn't a real option.</p><p>I was just surprised at this limitation of EF, since every database I've ever used lets you update the PK column. I wonder what the reasoning is behind this decision. Does EF not&nbsp;track original values like ADO.NET DataColumns do?</p><p></p></div></blockquote><p></p><p>I would imagine PK values are immutable for EF tracking and navigation (as FK relations).</p><p>I'd not want to deal with concurrency issues, meddling with PK values... perhaps that's one reason...</p><p>ADO.NET DataColumns -&nbsp;how does it handle data access concurrency with transient PK values?</p><p>Or is this PK value changing occurring offline?</p><p>What an odd strategy, changing PK values... I'm curious why is this being done?</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Question-about-EF/32f9e87ba75041679d77a10a010adb7b#32f9e87ba75041679d77a10a010adb7b</link>
		<pubDate>Thu, 15 Nov 2012 16:11:35 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Question-about-EF/32f9e87ba75041679d77a10a010adb7b#32f9e87ba75041679d77a10a010adb7b</guid>
		<dc:creator>JohnAskew</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/JohnAskew/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Question about EF</title>
		<description><![CDATA[<p>@<a href="/Forums/TechOff/Question-about-EF#c32f9e87ba75041679d77a10a010adb7b">JohnAskew</a>: Here's an example from our system:</p><p>PK = Master Analysis # (references other table), Piece Analysis #, and Effective Date</p><p>The analysis numbers are just generated IDs, but the effective date is chosen by the user setting up the analysis. Let's say they enter a date of November 15th, but it was supposed to be October 15th. With EF, they would have to remove the analysis and re-add it with the correct date.</p><p>Concurrency is not an issue because the row is locked in the database (another questionable choice, but it works for the limited cases where concurrency is an issue).</p><p>Could we have designed the table with an &quot;id&quot; column as the primary key and the set the three columns as a unique key? Sure, but most times the effective date is not changing.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Question-about-EF/70eaf0b777404aed8ce3a10a01172c4d#70eaf0b777404aed8ce3a10a01172c4d</link>
		<pubDate>Thu, 15 Nov 2012 16:56:26 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Question-about-EF/70eaf0b777404aed8ce3a10a01172c4d#70eaf0b777404aed8ce3a10a01172c4d</guid>
		<dc:creator>Scott</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/spivonious/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Question about EF</title>
		<description><![CDATA[<p></p><blockquote><div class="quoteText"><p></p><p><a class="permalink" title="Post Permalink" href="/Forums/TechOff/Question-about-EF/70eaf0b777404aed8ce3a10a01172c4d">16 minutes&nbsp;ago</a>, <a href="/Niners/spivonious">spivonious</a> wrote</p><p>@<a href="/Forums/TechOff/Question-about-EF#c32f9e87ba75041679d77a10a010adb7b">JohnAskew</a>: Here's an example from our system:</p><p>PK = Master Analysis # (references other table), Piece Analysis #, and Effective Date</p><p>The analysis numbers are just generated IDs, but the effective date is chosen by the user setting up the analysis. Let's say they enter a date of November 15th, but it was supposed to be October 15th. With EF, they would have to remove the analysis and re-add it with the correct date.</p><p>Concurrency is not an issue because the row is locked in the database (another questionable choice, but it works for the limited cases where concurrency is an issue).</p><p>Could we have designed the table with an &quot;id&quot; column as the primary key and the set the three columns as a unique key? Sure, but most times the effective date is not changing.</p><p></p></div></blockquote><p></p><p>while it may be a PIA to fix it I would think really hard about doing so....</p><p>seems like it should not really be that hard to fix and might allow you to make the whole system better.</p><p>changing a date should not make the whole thing break....&nbsp; and a PK should just be an internal pointer not a data value the users ever need to alter.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Question-about-EF/3b83427ada99413992f7a10a011db664#3b83427ada99413992f7a10a011db664</link>
		<pubDate>Thu, 15 Nov 2012 17:20:14 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Question-about-EF/3b83427ada99413992f7a10a011db664#3b83427ada99413992f7a10a011db664</guid>
		<dc:creator>figuerres</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/figuerres/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Question about EF</title>
		<description><![CDATA[<p></p><blockquote><div class="quoteText"><p></p><p><a class="permalink" title="Post Permalink" href="/Forums/TechOff/Question-about-EF/3b83427ada99413992f7a10a011db664">2 hours&nbsp;ago</a>, <a href="/Niners/figuerres">figuerres</a> wrote</p><p>*snip*</p><p>while it may be a PIA to fix it I would think really hard about doing so....</p><p>seems like it should not really be that hard to fix and might allow you to make the whole system better.</p><p>changing a date should not make the whole thing break....&nbsp; and a PK should just be an internal pointer not a data value the users ever need to alter.</p><p></p></div></blockquote><p></p><p>I agree that a PK should never be changed as a best practice.</p><p>I will also suggest making the&nbsp;change for an&nbsp;&quot;id&quot; column as PK, and those&nbsp;three columns as an unique index. Those other apps that read from these three columns wouldn't have to change at all, correct? If true, then the change is not so hard.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Question-about-EF/7eb4c98ed35a4857873ea10a01480b03#7eb4c98ed35a4857873ea10a01480b03</link>
		<pubDate>Thu, 15 Nov 2012 19:54:22 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Question-about-EF/7eb4c98ed35a4857873ea10a01480b03#7eb4c98ed35a4857873ea10a01480b03</guid>
		<dc:creator>JohnAskew</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/JohnAskew/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>