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
Nullable reference types #712
Comments
That would require you to support nullable types in your project, and use a new C# version?? |
So users shouldn't need to explicitly enable anything in their project files. |
But it would still require a new C# version?? |
Yes C# 8. For netstandard2.1 and netcore3.0 and above, users won't need to do anything. |
Ok, so could you give a simple example of the changes required on the generated code? |
A procedure public partial class UsersInClassResult
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public byte? Role { get; set; }
} The change would be to add a public string? Email { get; set; } |
Thanks, and the #nullable directive?? |
I missed some // <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable enable
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace EFCorePowerTools
{
public partial class UsersInClassResult
{
public int Id { get; set; }
public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public string? Email { get; set; }
public byte? Role { get; set; }
}
} |
Hmm what is the code after FirstName, is byte not a value type?? |
If you have
then you are saying that FirstName is not null, but there is no non-null value it's being initialized to, and
Yes the |
How would the code generation tool distinguish between FirstName/LastName and Email??? 😕 They are all strings ???
|
Presumably it gets info on nullability from SQL. It's certainly getting it correctly for value types at present (e.g. in the above, |
Sorry, I was mixing parameters and result set shape. So for a non-nullable string (and other reference types) , generate:
and for a nullable string (and other reference types), generate
Is that correctly understood? |
OK, interested in doing a PR? |
Currently I'm investigating 3 options for improving our database process (EFCorePowerTools / FSharp.Data.Sqlclient / SqlPlus.net). If we decide on EFCorePowerTools I can do a PR but if not I will not be able to. |
No worries, I will make the proposed change! |
@charlesroddie All good. |
I plan to implement this as an advanced option initially. |
…ure result sets fixes #712 Also fix NRE in Handler
Please add a row the warning appears on every row with string? |
@stgenov pls create an new issue with details about your csproj. |
Optional value-type results of stored procedures are correctly given as Nullable by EFCorePowerTools.
It would be good to have this apply to reference types too, e.g.
string?
in Result classes.This would make use of this library much more type-safe.
The text was updated successfully, but these errors were encountered: