Так что моя проблема заключается в следующем. При использовании Data Context ExecuteQuery (строковый запрос, параметры params object []) ( здесь ) я не могу пройти через ноль каким-либо образом фигуры или формы. Параметр, который начал это, был параметром SQL nvarchar, который должен позволять пустые значения.
Я прочитал эту статью по stackoverflow, в котором «use DBNull.Value» было помечено как ответ - поэтому я попробовал это, и ничего (так интересно, как это может быть ответом, если это не так Работа??!).
Вот пример кода, который я пытаюсь запустить (обратите внимание, это просто для проверки концепции):
var db = new Test1DataContext(Properties.Settings.Default.TestConnectionString);
var query = "EXEC UpInsertTest4 {0}, {1}";
// Works fine
var list1 = new List<object> { 1, "1" };
db.ExecuteQuery<UpInsertTest4Result>(query, list1.ToArray());
// Doesn't work
var list2 = new List<object> { 1, DBNull.Value };
db.ExecuteQuery<UpInsertTest4Result>(query, list2.ToArray());
Вот различные ошибки, которые я получаю:
null : A query parameter cannot be of type 'System.Object'.
default(string) : A query parameter cannot be of type 'System.Object'.
DBNull.Value : Unexpected type code: DBNull (which give this as a stack trrace)
at System.Data.Linq.SqlClient.SqlTypeSystem.Sql2005Provider.From(Type type, Nullable`1 size)
at System.Data.Linq.SqlClient.SqlTypeSystem.Sql2008Provider.From(Type type, Nullable`1 size)
at System.Data.Linq.SqlClient.SqlTypeSystem.ProviderBase.From(Type type)
at System.Data.Linq.SqlClient.SqlTypeSystem.ProviderBase.From(Object o)
at System.Data.Linq.SqlClient.SqlFactory.ValueFromObject(Object value, Type clrType, Boolean isClientSpecified, Expression sourceExpression)
at System.Data.Linq.SqlClient.QueryConverter.VisitConstant(ConstantExpression cons)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitUserQuery(String query, Expression[] arguments, Type resultType)
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 System.Data.Linq.DataContext.ExecuteQuery[TResult](String query, Object[] parameters)
at ConsoleApplication1.Program.Main(String[] args) in E:\TestBed\Testbed\ConsoleApplication1\Program.cs:line 36
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Из того, что я прочитал, я мог бы с этим проиграть! Это моя последняя попытка рва!
Большое спасибо,
Крис.