MoonStorm / FastCrud

fast .NET ORM for strongly typed people
MIT License
506 stars 128 forks source link

ForeignKey object not mapped #144

Closed pborgmans closed 5 years ago

pborgmans commented 5 years ago
    [Table("tblVIC_Nieuws_Omschrijving")]
    public class NewsDescriptionDto : BaseModel
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [ForeignKey(nameof(NewsDto))]
        public int Nieuws { get; set; }
        public NewsDto NewsDto { get; set; }

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public string Taal { get; set; }

        public bool IsDefault { get; set; }

        public string Samenvatting { get; set; }

        public string Inhoud { get; set; }

        public string Titel { get; set; }
    }

    [Table("tblVIC_Nieuws")]
    public class NewsDto : BaseModel
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public new int Id { get; set; }

        public DateTime? StartDatum { get; set; }

        public DateTime? EindDatum { get; set; }

        public string Categorie { get; set; }

        public string FotoUrl { get; set; }

        public string ZichtbaarVoorReseller { get; set; }

        public string ZichtbaarVoorKlant { get; set; }

        public string ZichtbaarVoorProspect { get; set; }
        public IEnumerable<NewsDescriptionDto> Descriptions { get; set; }
    }

When I try to find the NewsDto object, it gives me an error that NewsDescriptionDto cannot be mapped to NewsDto.

db.Find<NewsDto>(statement => statement
                    .Where($"{nameof(NewsDto.Id):C}=@Id")
                    .Include<NewsDescriptionDto>(join => join.InnerJoin())
                    .WithParameters(new { Id = id })).FirstOrDefault();

Am I doing something wrong?

Thanks!