You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.1 KiB
109 lines
3.1 KiB
// ========================================================================
|
|
//
|
|
// Copyright (C) 2016-2017 MARC CHEVALDONNE
|
|
// marc.chevaldonne.free.fr
|
|
//
|
|
// Module : Nounours.cs
|
|
// Author : Marc Chevaldonné
|
|
// Creation date : 2016-10-18
|
|
//
|
|
// ========================================================================
|
|
|
|
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace ex_042_006_EF_CF_One_to_One
|
|
{
|
|
/// <summary>
|
|
/// Nounours est une classe POCO, i.e. Plain Old CLR Object.
|
|
/// Elle a une relation 1-1 avec la classe CarnetDeSante via la propriété Carnet.
|
|
/// La clé primaire est générée lors de l'insertion en table (et est utilisée dans la classe CarnetDeSante
|
|
/// pour faire l'association. cf. CarnetDeSante).
|
|
[Table("TableNounours")]
|
|
public class Nounours
|
|
{
|
|
[Key]
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
public Guid UniqueId
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
public virtual CarnetDeSante Carnet { get; set; }
|
|
|
|
[Required]
|
|
[MaxLength(256)]
|
|
public string Nom
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[Column("Naissance")]
|
|
public DateTime DateDeNaissance
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[NotMapped]
|
|
public int NbPoils
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
/// <summary>
|
|
/// returns a hash code in order to use this class in hash table
|
|
/// </summary>
|
|
/// <returns>hash code</returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return Nom.GetHashCode();
|
|
}
|
|
|
|
/// <summary>
|
|
/// checks if the "right" object is equal to this Nounours or not
|
|
/// </summary>
|
|
/// <param name="right">the other object to be compared with this Nounours</param>
|
|
/// <returns>true if equals, false if not</returns>
|
|
public override bool Equals(object right)
|
|
{
|
|
//check null
|
|
if (object.ReferenceEquals(right, null))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (object.ReferenceEquals(this, right))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (this.GetType() != right.GetType())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return this.Equals(right as Nounours);
|
|
}
|
|
|
|
/// <summary>
|
|
/// checks if this Nounours is equal to the other Nounours
|
|
/// </summary>
|
|
/// <param name="other">the other Nounours to be compared with</param>
|
|
/// <returns>true if equals</returns>
|
|
public bool Equals(Nounours other)
|
|
{
|
|
return (this.Nom.Equals(other.Nom) && this.DateDeNaissance == other.DateDeNaissance);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{UniqueId}: {Nom} ({DateDeNaissance:dd/MM/yyyy}, {NbPoils} poils)";
|
|
}
|
|
|
|
}
|
|
}
|