我不知道为什么我不能使用InsertOnSubmit()
大家好,
我正在创建一个权限存储库,此代码来自我的书.
HI guys,
I am creating an Permission Repository and this code is from my book.
public void SavePermission(Permission permission)
{
using(FisharooDataContext dc = Connection.GetContext())
{
if(permission.PermissionID > 0)
{
<u>dc.Permissions.Attach(permission,true);</u>
}
else
{
<u> dc.Permissions.InsertOnSubmit(permision);</u>
}<u>
dc.SubmitChanges();</u>
}
}
使用dc.Permissions.Attach(permission,true)时出现错误.它给我一个错误,指出它不能接受两个以上的参数.
AND
什么时候尝试使用
I get error when i use dc.Permissions.Attach(permission,true).. it gives me an error saying it cant take more than 2 arguments.
AND
when is try using
dc.Permission.InsertOnSubmit(permission);
和
and
dc.SubmitChanges();
我的视觉工作室的智能感知无法识别InsertOnSubmit或SumbmitChanges
也许我应该使用使用声明,但我不知道该使用哪一个!
我什至将我的代码转给该网页
http://code.google.com/p/eboxshowsns/source/browse/trunk/EboxShowSNS.Core/DataAccess/Impl/PermissionRepository.cs?spec=svn6&r=6 [ ^ ]
但我没有发现任何区别.
请帮我解决上面提到的3个问题.
谢谢.
my visual studio''s intellisense cannot recognize InsertOnSubmit or SumbmitChanges
maybe i should use an using statment but i dont kno which!
and i even reffered my code to this webpage
http://code.google.com/p/eboxshowsns/source/browse/trunk/EboxShowSNS.Core/DataAccess/Impl/PermissionRepository.cs?spec=svn6&r=6[^][^]
but i dont find any differences.
Please help me out with my above 3 mentioned problems.
Thank you.
这是错字吗?
dc.Permission s .InsertOnSubmit(权限);
我确定它就是上面和链接的源代码中所说的那样.
我假设您的(Connection)conn.GetContent返回一个System.Data.Linq.DataContext实例?如果实例化了,那么当记录已经存在时,为什么还要附加记录呢?您是否正在使用某种形式的数据缓存?实现对特定记录的更改的方法是从表中选择记录,更新每个属性和每个属性,然后仅更新dc.SubmitChanges()(我认为:S)
您是否确定权限"表具有大写字母P,因为自动生成的dbml文件通常将其小写,如实体类型"permission"
如果我有所有这些错误,那么请在代码中发布证明,因为您可能错过了一个小错误.
希望这是有用的;)
is this a typo?
dc.Permissions.InsertOnSubmit(permission);
I''m sure it is as the code above and on the linked source says so.
I assume that your (Connection)conn.GetContent returns a System.Data.Linq.DataContext instance? If this has been instanciated then why would you need to attach a record to it when the record already exists? Are you using some form of data caching? The way that changes to a specific record would be acheived is to select the record out of the table, update eacha and every property and then just dc.SubmitChanges() (I think :S)
Are you sure that the "Permissions" table has a capital P as automatically generated dbml files usually put this to lower case, as with the entity type "permission"
If I have all of this wrong then please post the proof in code as there may be a small error there you have missed.
Hope this is useful ;)