Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 循环通过表适配器方法检查是否为标量_C#_Visual Studio - Fatal编程技术网

C# 循环通过表适配器方法检查是否为标量

C# 循环通过表适配器方法检查是否为标量,c#,visual-studio,C#,Visual Studio,目前我有大约30个表适配器,它们都有一个查询InsertAndReturnId。这是一个插入查询,返回最后一个插入的id。要使其工作,我必须在visual Studio数据集设计器中将查询的执行模式设置为Scalar 问题是,当我编辑或保存该查询时,它会将执行模式重置为非查询模式,有时我会忘记将其更改回来 这是一个真正的痛苦,因为它们都返回一个int值,而大多数代码只是将返回值强制转换为int 我已经了解了Visual Studio生成的内容,它看起来取决于它将添加的execute属性: ret

目前我有大约30个表适配器,它们都有一个查询InsertAndReturnId。这是一个插入查询,返回最后一个插入的id。要使其工作,我必须在visual Studio数据集设计器中将查询的执行模式设置为Scalar

问题是,当我编辑或保存该查询时,它会将执行模式重置为非查询模式,有时我会忘记将其更改回来

这是一个真正的痛苦,因为它们都返回一个int值,而大多数代码只是将返回值强制转换为int

我已经了解了Visual Studio生成的内容,它看起来取决于它将添加的execute属性:

returnValue = command.ExecuteScalar();

我宁愿不去检查这些方法的每一次使用并添加一个检查。或者为每个表适配器添加检查条件

是否可以在编译期间或在运行时循环使用VisualStudio生成的表适配器,并检查它们是作为标量还是非查询执行

比如:

foreach(var tableAdapterMethod in tableAdapterMethods)
{
    if(tableAdapterMethod.Name == "InsertAndReturnId")
    {
       if(tableAdapterMethod.ExecuteType != "Scalar")
       {
            // throw warning and stop further execution.
        }
     }
 }
foreach(var tableAdapterMethod in tableAdapterMethods)
{
    if(tableAdapterMethod.Name == "InsertAndReturnId")
    {
       if(tableAdapterMethod.ExecuteType != "Scalar")
       {
            // throw warning and stop further execution.
        }
     }
 }