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

Default value set to entity when retrieve data is null #27743

Closed
Zefek opened this issue Apr 1, 2022 · 2 comments
Closed

Default value set to entity when retrieve data is null #27743

Zefek opened this issue Apr 1, 2022 · 2 comments

Comments

@Zefek
Copy link

Zefek commented Apr 1, 2022

Hello,

I would like to ask about possibility to set default value to property when retrieve data from database.
I need to use stored procedure because of backward compatibility with another part of system. This stored procedure can return column with null value. It means property should be nullable (i.e. public int? Count { get; set; }.
But because of backward compatibility I cannot use nullable property.
There is any method on Property (e.i. method DefaultValueOnRetreive(0)) how to say default value when retrieve data is null?

Thanks.

@ajcvickers
Copy link
Contributor

@Zefek You could use a value converter for this. This could also be done using #10768, when implemented. However, be aware that this could cause problems if the converted value is part of a key or foreign key--see #26209 and #26210.

@Zefek
Copy link
Author

Zefek commented Apr 1, 2022

Thank you. I aware of some kind of problem but I want to use it for query (read) model where each entity is configured as HasNoKey and will not be saved back to database.
Command model is configured with nullable properties and there is some validation to check if value is null.

@Zefek Zefek closed this as completed Apr 1, 2022
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants