悬赏园豆:20
[已解决问题]
解决于 2007-11-29 09:59
<DIV style="FONT-SIZE: 11pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: consolas">
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">NorthwindDataContext</SPAN> db = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">NorthwindDataContext</SPAN>();</P>
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">Employee</SPAN> emp = db.Employees.First();</P>
<P style="MARGIN: 0px"> </P>
<P style="MARGIN: 0px"><SPAN style="COLOR: #2b91af">NorthwindDataContext</SPAN> db2 = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">NorthwindDataContext</SPAN>();</P>
<P style="MARGIN: 0px">db2.Employees.Attach(emp);</P>
<P style="MARGIN: 0px"> </P>
<P style="MARGIN: 0px">在rtm版的vsts2008中,不支持跨datacontext的对象attach。如果我的emp 在业务层从其他方法获取,就无法在新的datacontext里使用了,大家有没有解决方法。</P></DIV>
问题补充:
可以参考这两个链接
http://blogs.msdn.com/dinesh.kulkarni/archive/2007/10/08/attach-if-you-have-something-detached.aspx
http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/11/21/linq-to-sql-table-lt-t-gt-detach-method-does-not-exist.aspx
Jeffery zhao: 你确认是在rtm下吗,我的程序老是会报错,而且上面两个链接里也明确了attach方法不可以这么来用
Tom Song 在这篇blog里给出了解决方案
http://www.cnblogs.com/126/archive/2007/11/28/976006.html