Share via

Build Failed as migration the class

sblb 1,236 Reputation points
2021-11-12T17:41:30.737+00:00

Hi

below I've the class and I want to do the migration with it

namespace WebApp3.Shared.Models
{
    public partial class Developer
    {

 public DateTime? DateSolde { get; set; }
 public List<string> Labels { get; set; }
 public bool IsOpen
 {
 get
 {
 return this.DateSolde .HasValue;
 }
 set
 {
 if (!this.DateSolde .HasValue)
 {
 this.DateSolde = DateTime.Now;
 }
 }
 }
    }
}

When I launched add-migration Initial The build is Failed. I don't understand why? Have you an idea?
Thanks in advance

Developer technologies | .NET | Blazor
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Answer accepted by question author

Anonymous
2021-11-15T03:30:43.827+00:00

Hi @sblb ,

  int close = context.Developers.Count(a => a.DateSolde.Month == DateTime.Today.Month);    

The problem is that when I put DateTime? DateSolde I've the does not include a month definition.

Since the DateSolde property is nullable, before the Count method, add a ToList() method, and for the DateSolde property, add a ? character, like this:

int close = context.Developers.ToList().Count(a => a.DateSolde?.Month == DateTime.Today.Month);  

The result as below:

149336-image.png


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best regards,
Dillion

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. sblb 1,236 Reputation points
    2021-11-15T08:36:46.143+00:00

    Hi, thanks to your reply. I added ? and I've always the problem.
    149286-capture.png

    Was this answer helpful?


  2. sblb 1,236 Reputation points
    2021-11-14T11:15:23.25+00:00

    The build is fail because I've put in controller

     public IActionResult MonthlyStats()
            {
    
                int close = context.Developers.Count(a => a.DateSolde.Month == DateTime.Today.Month);
    
                .....
    
            }
    

    The problem is that when I put DateTime? DateSolde I've the does not include a month definition.
    What can I do about it?

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.