小编Jac*_*cek的帖子

将可空的guid传递给存储过程

当我在我的c#代码中将可空的guid参数传递给存储过程时.我得到例外:

System.Data.SqlClient.SqlException(0x80131904):'@customerGuid'附近的语法不正确.

var userNameSqlParam = new SqlParameter
{
    ParameterName = "userName",
    Value = userName,
    DbType = DbType.String
};

var customerGuidSqlParam = new SqlParameter
{
    ParameterName = "customerGuid",
    Value = customerGuid,
    DbType = DbType.Guid
};

var rows = _dbContext.Database
    .SqlQuery<CurrentUserContextWithoutCustomer>
        ("EXEC [dbo].[GetCurrentUserContext] @userName @customerGuid",
        userNameSqlParam, customerGuidSqlParam)
    .ToList();
Run Code Online (Sandbox Code Playgroud)

因此,当我通过SQL事件探查器查看我得到的内容时

exec sp_executesql 
N'EXEC [dbo].[GetCurrentUserContext] @userName @customerGuid',
N'@userName nvarchar(4),@customerGuid uniqueidentifier',
@userName=N'gir1',@customerGuid=default
Run Code Online (Sandbox Code Playgroud)

我在查询结束时看到默认值.它会产生问题.有存储过程的标题

ALTER PROCEDURE [dbo].[GetCurrentUserContext]
    @userName nvarchar(100),
    @customerGuid uniqueidentifier
AS
Run Code Online (Sandbox Code Playgroud)

如何将可空的guid作为存储过程参数传递给sql.

c# sql sql-server stored-procedures entity-framework

1
推荐指数
1
解决办法
3414
查看次数

我在哪里可以找到Linq ThenInclude方法?

我看到一些包含ThenInclude的 LINQ代码示例.我在哪里可以找到这样的方法?在外部库或其他命名空间中.

我想用这样的方法来获取派生数据,但我找不到这样的方法或者你知道其他解决方案

        return _dbContext.Goals
            .Where(p => p.Owner.Id == userId)
            .Include(p => p.GoalExpectation)
                .ThenInclude<RangeGoalExpectation>(p => p.MinValue)
                .ThenInclude<RangeGoalExpectation>(p => p.MaxValue)
                .ThenInclude<SpecifiedGoalExpectation>(p => p.Value)
Run Code Online (Sandbox Code Playgroud)

c# linq model-view-controller entity-framework

1
推荐指数
1
解决办法
2316
查看次数

在C#中删除对象

在dotNET中我们可以编写非托管代码,在哪里可以动态分配内存(通过关键字:stackalloc,new),使用指针等.
可以释放内存(例如通过像C++中的delete这样的东西)?

.net c#

0
推荐指数
1
解决办法
684
查看次数

将控制台应用程序编译为MSIL代码

我使用Visual Studio 2012,我在那里编写简单的控制台应用程序.有谁知道如何从我的C#代码中获取MSIL代码?
我希望在没有ILDASM的编译之后看到它,可以自动执行此过程

.net c# cil

0
推荐指数
1
解决办法
118
查看次数

字节枚举中的字符串

可能重复:
C#枚举 - 我的枚举可以有友好的名字吗?
使用枚举属性将字符串转换为枚举

我有字节值的枚举:

enum MarketingEventType : byte {MARKETING_CAMPAIGN, TELESALES, MARKETING_ACTIONS};
Run Code Online (Sandbox Code Playgroud)

我想给出所有元素名称,我将通过ToSting()方法获得.例如:

MarketingEventType.TELESALES.ToString(); // I get "bla bla bla"
MarketingEventType.MARKETING_ACTIONS.ToString(); // I get "la la la"
Run Code Online (Sandbox Code Playgroud)

从BYTE到STRING没有改变类型的enum是可能的吗?

.net c# string enums

0
推荐指数
1
解决办法
1247
查看次数

对象和小数之间的转换?

为什么我不能将对象转换为十进制(代码低于,record["Cost"]等于1 (int))?

我得到以下错误

'无法取消装箱记录["费用"]'

我将使用TryParse方法,但我不明白这个错误的来源是什么.

cost = (decimal?) record["Cost"];
Run Code Online (Sandbox Code Playgroud)

.net c# type-conversion

0
推荐指数
1
解决办法
156
查看次数

Apple推送通知中的自定义JSON

我想在推送通知中向Apple手机发送自定义JSON,而无需任何其他信息.
我会发送类似的东西:

{
    message: "Message bla bla"
    , type: 1
    , data: "Tekst" 
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

c# push-notification apple-push-notifications ios

0
推荐指数
1
解决办法
1103
查看次数

SQL Server 2012:提交与存储过程中的开始 tran 不匹配

我在 SQL Server 2012 Express 中编写了这个存储过程。

ALTER PROCEDURE [Dictionaries].[InsertCountry]
(@p_countryName nvarchar(128)
 , @ret_countryId int OUTPUT)
AS
BEGIN
    DECLARE @TransactionName VARCHAR(20) = 'INST_COUNTRY';

    BEGIN TRANSACTION @TransactionName;

IF len(@p_countryName) <= 3
BEGIN
        SET @ret_countryId = null
        ROLLBACK TRANSACTION @TransactionName;
END

INSERT INTO [Dictionaries].[CountryDetails] (name)
VALUES (@p_countryName);    

SET @ret_countryId = @@IDENTITY

INSERT INTO [Dictionaries].[Places] (name, Discriminator , CountryDetails_Id, RegionDetails_Id, CityDetails_Id)
VALUES (@p_countryName, 'Country' , @ret_countryId, null, null);

COMMIT TRANSACTION @TransactionName;
END
Run Code Online (Sandbox Code Playgroud)

我以这种方式使用这个方法,但我收到消息

COMMIT TRANSACTION 请求没有对应的 BEGIN TRANSACTION。

代码:

declare @ret int = null …
Run Code Online (Sandbox Code Playgroud)

sql sql-server stored-procedures transactions

0
推荐指数
1
解决办法
1048
查看次数

WPF 中的注入和无参数构造函数

我有 WPF 中的用户控制代码(如下)。我使用 nInject 作为 IocContainer。我在 App 类的 OnStartup 事件中初始化 ioc。

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        var iocContainer = IocContainer.Get();

        iocContainer.Bind<CreateRemindPopup>().To<CreateRemindPopup>();
        iocContainer.Bind<MainWindow>().To<MainWindow>();

        Current.MainWindow = iocContainer.Get<MainWindow>();
        Current.MainWindow.Show();
    }
Run Code Online (Sandbox Code Playgroud)

如果我删除无参数构造函数,则在应显示控件时会出现 NullReferenceException 异常。当存在无参数构造函数时,不会执行显示内容的代码。

我的问题是如何强制 WPF 使用参数执行构造函数?我不想删除无参数构造函数,因为这样我就在 VisualStudio 中丢失了设计器。

public partial class RemindersListing : UserControl
{
    private readonly IReminderReadLogic _reminderReadLogic;

    public ObservableCollection<Reminder> Reminders { get; set; }

    public RemindersListing()
    {
    }

    public RemindersListing(IReminderReadLogic reminderReadLogic)
    {
        _reminderReadLogic = reminderReadLogic;
        InitializeComponent();

        var list = _reminderReadLogic.Get();
        Reminders = new ObservableCollection<Reminder>(list);
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# wpf dependency-injection ninject

0
推荐指数
1
解决办法
1424
查看次数

什么是Windows Azure存储的默认顺序?

当我在服务器资源管理器中通过Visual Studio检查Windows Azure存储表内容时,我对这个日期处于混乱状态印象深刻.

什么是Windows Azure存储的默认顺序?我需要有关订单和方向的信息.

.net c# sorting azure azure-storage

0
推荐指数
1
解决办法
381
查看次数