none
Generic function for generating primary key value, Entity Framework RRS feed

  • Question

  • I have a stored procedure which generates next primary key value from a given table.

    Create procedure spDTAutoNumberGeneration(@tableName as varchar(50),@PKeyColumn as varchar(50),@NextNumber as int output)      
    As      
    BEGIN      
    declare @AutoSlNo int      
    declare @CompanyCode varchar(5)      
    declare @MaxSlno varchar(20)    
    declare @StrSQL as varchar(4000)      
    
    set @CompanyCode = (select top 1 def_comp_Loc_IDForDTS from absSettings)    
    
    create table #maxSlNo  (maxSlNo int)    
    --set @strsql=''    
    
    set @strSQL = 'select max(' + @PKeyColumn + ') + 1 from ' + @tableName + ' where left('  + @PKeyColumn + ',2 ) = ' + @CompanyCode + ' and ' + @PKeyColumn + ' >10000000 '      
    
    insert into #maxSlNo exec (@strSQL)    
    
    select @MaxSlno=maxSLNo from #MaxSlno    
    
    if @MaxSlno is null      
    begin      
         set @NextNumber= cast(@CompanyCode as varchar(2)) + '0000001'    
    end    
    else    
    begin    
        set @NextNumber=@MaxSlno    
    end    
    
    END    

    How i can do the same in Ef 4.3.

    Thanks in Advance

    Sreejith N P

    Tuesday, June 26, 2012 11:37 AM

Answers

All replies