Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. My linq update logic is not updating. help!

My linq update logic is not updating. help!

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqhelpannouncement
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael J Eber
    wrote on last edited by
    #1

    I have a database containing a key tracker table. The table has a single record with 2 fields, an alpha prefix and a numeric suffix. I get the record and perform all of my changes into the located record. Yet, inspite of doing a SubmitChanges, my table entry remains unchanged. My logic handles the records as follows:

    		lock ( threadLock )
    		{
    			CrossConnectKeyTracker key = new CrossConnectKeyTracker( );
    			using ( MasterDataContext context = new MasterDataContext( connectionString ) )
    			{
    				key = ( from k in context.CrossConnectKeyTrackers
    							select k ).SingleOrDefault( );
    				if ( key == null )
    				{
    					key = new CrossConnectKeyTracker( );
    					key.CharacterPrefix = "AA";
    					key.NumericSuffix = 00001;
    					context.CrossConnectKeyTrackers.InsertOnSubmit( key );
    					context.SubmitChanges( );
    					return String.Concat( key.CharacterPrefix, key.NumericSuffix.ToString( ).PadLeft( 5, '0' ) );
    				}
    
    				if ( key.NumericSuffix < 99999 )
    					key.NumericSuffix++;
    				else
    				{
    					int value;
    					if ( key.CharacterPrefix\[ 1 \] != 'Z' )
    						value = Convert.ToInt32( key.CharacterPrefix\[ 1 \] );
    					else
    						value = Convert.ToInt32( key.CharacterPrefix\[ 0 \] );
    					value++;
    					char newValue = Convert.ToChar( value );
    					if ( key.CharacterPrefix\[ 1 \] == 'Z' )
    						key.CharacterPrefix = string.Concat( newValue, key.CharacterPrefix\[ 1 \] );
    					else
    						key.CharacterPrefix = string.Concat( key.CharacterPrefix\[ 0 \], newValue );
    					key.NumericSuffix = 00001;
    				}
    				context.SubmitChanges( );
    			}
    			return String.Concat( key.CharacterPrefix, key.NumericSuffix.ToString( ).PadLeft( 5, '0' ) );
    
    A M 2 Replies Last reply
    0
    • M Michael J Eber

      I have a database containing a key tracker table. The table has a single record with 2 fields, an alpha prefix and a numeric suffix. I get the record and perform all of my changes into the located record. Yet, inspite of doing a SubmitChanges, my table entry remains unchanged. My logic handles the records as follows:

      		lock ( threadLock )
      		{
      			CrossConnectKeyTracker key = new CrossConnectKeyTracker( );
      			using ( MasterDataContext context = new MasterDataContext( connectionString ) )
      			{
      				key = ( from k in context.CrossConnectKeyTrackers
      							select k ).SingleOrDefault( );
      				if ( key == null )
      				{
      					key = new CrossConnectKeyTracker( );
      					key.CharacterPrefix = "AA";
      					key.NumericSuffix = 00001;
      					context.CrossConnectKeyTrackers.InsertOnSubmit( key );
      					context.SubmitChanges( );
      					return String.Concat( key.CharacterPrefix, key.NumericSuffix.ToString( ).PadLeft( 5, '0' ) );
      				}
      
      				if ( key.NumericSuffix < 99999 )
      					key.NumericSuffix++;
      				else
      				{
      					int value;
      					if ( key.CharacterPrefix\[ 1 \] != 'Z' )
      						value = Convert.ToInt32( key.CharacterPrefix\[ 1 \] );
      					else
      						value = Convert.ToInt32( key.CharacterPrefix\[ 0 \] );
      					value++;
      					char newValue = Convert.ToChar( value );
      					if ( key.CharacterPrefix\[ 1 \] == 'Z' )
      						key.CharacterPrefix = string.Concat( newValue, key.CharacterPrefix\[ 1 \] );
      					else
      						key.CharacterPrefix = string.Concat( key.CharacterPrefix\[ 0 \], newValue );
      					key.NumericSuffix = 00001;
      				}
      				context.SubmitChanges( );
      			}
      			return String.Concat( key.CharacterPrefix, key.NumericSuffix.ToString( ).PadLeft( 5, '0' ) );
      
      A Offline
      A Offline
      Andreas X
      wrote on last edited by
      #2

      Have you got a Primary Key on the data table object in the dbml file? This might cause similar problems.

      Andreas Johansson
      IT Professional at Office IT Partner i Norrbotten Sweden
      What we don't know. We learn.
      What you don't know. We teach

      1 Reply Last reply
      0
      • M Michael J Eber

        I have a database containing a key tracker table. The table has a single record with 2 fields, an alpha prefix and a numeric suffix. I get the record and perform all of my changes into the located record. Yet, inspite of doing a SubmitChanges, my table entry remains unchanged. My logic handles the records as follows:

        		lock ( threadLock )
        		{
        			CrossConnectKeyTracker key = new CrossConnectKeyTracker( );
        			using ( MasterDataContext context = new MasterDataContext( connectionString ) )
        			{
        				key = ( from k in context.CrossConnectKeyTrackers
        							select k ).SingleOrDefault( );
        				if ( key == null )
        				{
        					key = new CrossConnectKeyTracker( );
        					key.CharacterPrefix = "AA";
        					key.NumericSuffix = 00001;
        					context.CrossConnectKeyTrackers.InsertOnSubmit( key );
        					context.SubmitChanges( );
        					return String.Concat( key.CharacterPrefix, key.NumericSuffix.ToString( ).PadLeft( 5, '0' ) );
        				}
        
        				if ( key.NumericSuffix < 99999 )
        					key.NumericSuffix++;
        				else
        				{
        					int value;
        					if ( key.CharacterPrefix\[ 1 \] != 'Z' )
        						value = Convert.ToInt32( key.CharacterPrefix\[ 1 \] );
        					else
        						value = Convert.ToInt32( key.CharacterPrefix\[ 0 \] );
        					value++;
        					char newValue = Convert.ToChar( value );
        					if ( key.CharacterPrefix\[ 1 \] == 'Z' )
        						key.CharacterPrefix = string.Concat( newValue, key.CharacterPrefix\[ 1 \] );
        					else
        						key.CharacterPrefix = string.Concat( key.CharacterPrefix\[ 0 \], newValue );
        					key.NumericSuffix = 00001;
        				}
        				context.SubmitChanges( );
        			}
        			return String.Concat( key.CharacterPrefix, key.NumericSuffix.ToString( ).PadLeft( 5, '0' ) );
        
        M Offline
        M Offline
        Michael J Eber
        wrote on last edited by
        #3

        :laugh: It looks like you ran into exactly my issue. I have a keytracker table doing the same thing and it wasn't updating and I wanted to pull out my hair. Just change your table def as so: KeyFile primarykey int default 666 KeyPrefix ... KeySuffix ... I then always get my record with the 666 key and my update logic works! :doh:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups