Last active
August 29, 2015 14:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SqlDataContext : Miago.Data.Linq.DataContext | |
{ | |
public SqlDataContext(string nameOrConnectionString) | |
: base(nameOrConnectionString) { } | |
protected override string ParameterNamePrefix | |
{ | |
get { return "@p"; } | |
} | |
protected override System.Data.Common.DbParameter OnCreateParameter(System.Data.Common.DbCommand cmd, string name, object value) | |
{ | |
var par = cmd.CreateParameter() as System.Data.SqlClient.SqlParameter; | |
par.ParameterName = name; | |
if (value != null) | |
{ | |
if (value.GetType() == typeof(short)) | |
par.SqlDbType = SqlDbType.SmallInt; | |
else if (value.GetType() == typeof(int)) | |
par.SqlDbType = SqlDbType.Int; | |
else if (value.GetType() == typeof(long)) | |
par.SqlDbType = SqlDbType.BigInt; | |
else if (value.GetType() == typeof(float)) | |
par.SqlDbType = SqlDbType.Real; | |
else if (value.GetType() == typeof(double)) | |
par.SqlDbType = SqlDbType.Float; | |
else if (value.GetType() == typeof(decimal)) | |
par.SqlDbType = SqlDbType.Decimal; | |
else if (value.GetType() == typeof(DateTime)) | |
par.SqlDbType = SqlDbType.DateTime; | |
else if ((value.GetType() == typeof(string) && value.ToString().Length > 8000)) | |
par.SqlDbType = SqlDbType.Text; | |
} | |
par.Value = value; | |
return par; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment