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

Chapter 03 --> BlazorHolData ---> Add New Person causes an exception if Data.Database.People is emptied first #1

Open
jhogan05 opened this issue Dec 16, 2024 · 0 comments

Comments

@jhogan05
Copy link

Possible solution is to check first. There are other solutions on StackOverflow for this issue
(e.g https://stackoverflow.com/questions/6966680/max-return-value-if-empty-query)

   else
    {
        int newtId = Data.Database.People.Any() ?  Data.Database.People.Max(p => p.Id) + 1 : 1;
        Person!.Id = newtId;
        Data.Database.People.Add(Person);
    }
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

1 participant