I have an odd issue I have never seen before. Entity framework is returning a NULL object in a navigational property collection. I am accessing it in a circular manner though when I view it. You can see the screenshot below on the collection and the NULL object. I also gave the path below. Any clue why this is happening?
I caught this because AutoMapper didnt like it.
`"Missing type map configuration or unsupported mapping.\n\nMapping types:\r\nDivision -> DivisionModel\r\nTournaments.Data.Entities.Division -> Tournaments.Models.Divisions.DivisionModel\n\nDestination path:\nList`1[0].Event.Divisions.Divisions1[1]\n\nSource value:\nTournaments.Data.Entities.Division"`
Entity Path
DivisionBracket -> Division - Event -> List<Divisions> (has NULL and original Division)
Division.cs
[Table("Division", Schema = "")]
public class Division : BaseEntity
{
public int EventId { get; set; }
[ForeignKey("EventId")]
public Event Event { get; set; }
Event.cs
[Table("Event", Schema = "")]
public class Event : BaseEntity
{
[InverseProperty("Event")]
public virtual ICollection<Division> Divisions { get; set; }
Mapping
modelBuilder.Entity<Division>() .HasRequired(a => a.Event) .WithMany() .HasForeignKey(u => u.EventId).WillCascadeOnDelete(true);
I think that Division has mising mapping configuration. Probably you need to add relation mapping on DivisionMap.cs (1 to N mapping)
For ex
It cause this error
this.HasOptional(a => a.Occupation). WithMany() .HasForeignKey(c => c.OccupationId);
Correct way
this.HasOptional(a => a.Occupation). WithMany(x=>x.Employee) .HasForeignKey(c => c.OccupationId);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.