Dear Team,
I have a stored procedure...below the code of stored procedure in SQL.....I have googled but not any statisfied result and I tried to solve itself but could not solve and finaly i m helpless to ask the code project team.....this stored procedure is working fine without using linq.I have given small snippet of my code as follows
ALTER PROCEDURE [dbo].[SP_Get_Next_Id]
(
@Table_Name varchar(40),
@Column_Name varchar(40),
@SQL_Ret int output
)
AS
Declare @SQL_MAX nVarchar(100)
DECLARE @ParmDefinition NVARCHAR(500)
BEGIN
SET NOCOUNT ON
Begin
set @SQL_MAX='Select @SQL_MAX_OUT=isnull(Max('+@Column_Name+'),0)+1 From '+@Table_Name
SET @ParmDefinition = N'@SQL_MAX_OUT varchar(30) OUTPUT'
exec sp_executesql @SQL_MAX,@ParmDefinition,@SQL_MAX_OUT=@SQL_Ret OUTPUT
End
END
-------LINQ MAPPING----
using System.Data;
using System.Configuration;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Linq.Mapping;
using System.Reflection;
public class DB_DataContext:DataContext
{
public DB_DataContext()
: base(@"Data source=.\SQLEXPRESS;AttachDbFileName=|Datadirectory|\Data\Fleet_CMMS.MDF;
Integrated Security=True;User Instance=True")
{}
[Function(Name = "dbo.SP_Get_Next_Id")]
public ISingleResult<int> SP_Get_Next_Id([Parameter(DbType = "Varchar(40)")] string TableName,
[Parameter(DbType = "Varchar(40)")] string Column_Name,
[Parameter(DbType = "int")] ref int SQL_Ret)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), TableName, Column_Name, SQL_Ret);
return (ISingleResult<int>)(result.ReturnValue);
}
}
----CALLING CODE----
int return_variable=0;
DB_DataContext Db_dc = new DB_DataContext();
Db_dc.SP_Get_Next_Id("CMMS_DEPOT_MASTER", "Depot_ID", ref return_variable);
IT GIVES ERROR
System.InvalidOperationException: The type 'System.Int32' must declare a default (parameterless) constructor in order to be constructed during mapping. at System.Data.Linq.SqlClient.Translator.BuildProjectionInternal(SqlExpression item, MetaType rowType, IEnumerable`1 members, Boolean allowDeferred, SqlLink link, Expression source) at System.Data.Linq.SqlClient.Translator.BuildProjection(SqlExpression item, MetaType rowType, Boolean allowDeferred, SqlLink link, Expression source) at System.Data.Linq.SqlClient.QueryConverter.TranslateStoredProcedureCall(MethodCallExpression mce, MetaFunction function) at System.Data.Linq.SqlClient.QueryConverter.VisitMappedFunctionCall(MethodCallExpression mc) at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) at System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node) at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations) at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) at System.Data.Linq.DataContext.ExecuteMethodCall(Object instance, MethodInfo methodInfo, Object[] parameters) at DB_DataContext.SP_Get_Next_Id(String TableName, String Column_Name, Int32& SQL_Ret) in d:\sukhen\Projects\ASP.NET\Fleet_CMMS\App_Code\DB_DataContext.cs:line 34 at Forms_frmDepot.btnSave_Click(Object sender, EventArgs e) in d:\sukhen\Projects\ASP.NET\Fleet_CMMS\Forms\frmDepot.aspx.cs:line 68
[edit]SHOUTING removed - OriginalGriff[/edit]