Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table Valued Functions and Nullable parameters. #379

Closed
oruchreis opened this issue Feb 7, 2018 · 2 comments
Closed

Table Valued Functions and Nullable parameters. #379

oruchreis opened this issue Feb 7, 2018 · 2 comments

Comments

@oruchreis
Copy link

oruchreis commented Feb 7, 2018

Hi,
I have table valued functions which have nullable parameters. But the generator generates parameters' values with GetValueOrDefault function not DBNull.Value. So if the function has int? parameter, and its value is null, then it creates function query using "0" not "NULL". So I've changed generator code like this:

public static readonly Func<StoredProcedure, string> WriteTableValuedFunctionDeclareSqlParameter = sp =>
    {
        var sb = new StringBuilder();
        foreach (var p in sp.Parameters.OrderBy(x => x.Ordinal))
        {
            sb.AppendLine(string.Format("            var {0}Param = new System.Data.Entity.Core.Objects.ObjectParameter(\"{1}\", typeof({2})) {{ Value = (object){3} }};",
                p.NameHumanCase,
                p.Name.Substring(1),
                p.PropertyType,
                p.NameHumanCase + (p.Mode == StoredProcedureParameterMode.In && NotNullable.Contains(p.PropertyType.ToLowerInvariant()) ? string.Empty : " ?? System.DBNull.Value/*.GetValueOrDefault()*/" )));
        }
        return sb.ToString();
    };

Is this a bug or am I doing wrong somewhere?

@sjh37
Copy link
Owner

sjh37 commented Feb 7, 2018

Thanks. This will be in the next release.

@sjh37 sjh37 closed this as completed Feb 7, 2018
sjh37 added a commit that referenced this issue Feb 7, 2018
@sjh37
Copy link
Owner

sjh37 commented Feb 26, 2018

Released in v2.36.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants