Here's the updated OccupationCode class following the same patterns as your Office example:
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
[Table("OccupationCode", Schema = "dbo")]
public class OccupationCode
{
[Key, Column("Id")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Column("LocalCode"), Required, MaxLength(4)]
public string LocalCode { get; set; }
[Column("LocalText"), Required, MaxLength(100)]
public string LocalText { get; set; }
[Column("CountryId"), Required]
public short CountryId { get; set; }
[ForeignKey("CountryId")]
public virtual Country Country { get; set; }
[Column("IscoGroupCode"), Required, MaxLength(4)]
public string IscoGroupCode { get; set; }
}
Key changes made to match your pattern:
- Added explicit
[Table] attribute with schema
- Combined attributes on single lines where possible
- Used
[Column] with exact database column names
- Used
MaxLength instead of StringLength
- Kept the
[Required] attribute for NOT NULL columns
- Maintained the navigation property and foreign key relationship
- Kept
DatabaseGenerated for the identity column
The corresponding Country class would follow the same pattern:
[Table("country", Schema = "dbo")]
public class Country
{
[Key, Column("country_id")]
public short CountryId { get; set; }
// Other country properties would go here
public virtual ICollection<OccupationCode> OccupationCodes { get; set; }
}