Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL LINQ C#4.0
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>
     }
}
 
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();
 
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.
Posted 13-May-12 14:51pm
Sipherz431
Edited 13-May-12 17:44pm
v2
Comments
SASS_Shooter at 14-May-12 17:21pm
   
For the InsertOnSubmit and SubmitChanges issues, did you look to see if you have
using System.Data.Linq?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Wink | ;)
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 329
3 Sergey Alexandrovich Kryukov 290
4 CPallini 219
0 OriginalGriff 697
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 495
3 thatraja 370
4 Sergey Alexandrovich Kryukov 344


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 16 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100