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

New rule S3363 (C#): Date and time should not be used as types for primary keys #7086

Closed
8 of 9 tasks
csaba-sagi-sonarsource opened this issue Apr 14, 2023 · 1 comment · Fixed by #7471
Closed
8 of 9 tasks
Assignees
Labels
Area: C# C# rules related issues. Type: New Rule Implementation for a rule that HAS been specified.
Projects
Milestone

Comments

@csaba-sagi-sonarsource
Copy link
Contributor

csaba-sagi-sonarsource commented Apr 14, 2023

Implement new rule S3363: DateTime and DateTimeOffset types should not be used as primary keys.

The rule raises an issue if: Entity Framework, or Entity Framework Core dependencies are found and a class contains a property of temporal type (DateTime, DateTimeOffset, etc.) that is either named Id, <type name>Id or decorated by the [Key] or [PrimaryKey] attribute.

  • Implement Rule S3363 for C#
  • Update RSPEC
  • Create a basic C# implementation and basic test cases for .NET Core: DateTime, DateTimeOffset, TimeSpan
  • Add test cases for EF 6.0 (.NET Framework)
  • Add Test cases for TimeOnly and DateOnly types EF Core 7.0+)
  • Skip validation if the project has no EF dependency
  • Add test cases for [PrimaryKey] attribute (EF Core 7.0+)
  • Optional: Add test cases for EF Fluent API (as FNs)
  • Optional: cover temporal types from 3rd party libraries (like NodaTime)
  • Optional: Add new ITs if necessary (if no IT covers the rule)
@csaba-sagi-sonarsource csaba-sagi-sonarsource added Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. Type: New Rule Implementation for a rule that HAS been specified. labels Apr 14, 2023
@costin-zaharia-sonarsource costin-zaharia-sonarsource added this to the 9.4 milestone Jun 8, 2023
@github-actions github-actions bot added this to To do in Best Kanban Jun 8, 2023
@zsolt-kolbay-sonarsource
Copy link
Contributor

zsolt-kolbay-sonarsource commented Jun 9, 2023

The DateOnly and TimeOnly types are also supported in Entity Framework Core 7.0 and above, so it's worth adding them to this rule.

@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource removed their assignment Jun 9, 2023
@costin-zaharia-sonarsource costin-zaharia-sonarsource removed this from the 9.4 milestone Jun 12, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource moved this from To do to In progress in Best Kanban Jun 19, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource linked a pull request Jun 20, 2023 that will close this issue
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title New rule S3363: DateTime and DateTimeOffset types should not be used as primary keys New rule S3363 (C#): Timestamps should not be used as primary keys Jun 21, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource removed the Area: VB.NET VB.NET rules related issues. label Jun 21, 2023
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Jun 21, 2023
@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Jun 22, 2023
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Jun 22, 2023
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Jun 22, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title New rule S3363 (C#): Timestamps should not be used as primary keys New rule S3363 (C#): Date and time should not be used as a type for primary keys Jun 23, 2023
Best Kanban automation moved this from Review approved to Validate Peach Jun 23, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource moved this from Validate Peach to Done in Best Kanban Jun 25, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title New rule S3363 (C#): Date and time should not be used as a type for primary keys New rule S3363 (C#): Date and time should not be used as types for primary keys Jun 28, 2023
@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource added this to the 9.5 milestone Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: New Rule Implementation for a rule that HAS been specified.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

4 participants