I have two tables MeetingPollingQuestion and MeetingPollingParts. Meeting polling question pk MeetingPollingQuestionId is a foreign key to meeting polling parts. I would like to insert the MeetingPollingQuestion and then use the PK to then insert rows into MeetingPollingParts. I am getting this error about "No mapping specified for properties" and I am not sure what that means.
My code:
mf.MeetingPollingId = mpq.MeetingPollingId;
mf.MeetingPollingQuestionType = mpq.MeetingPollingQuestionType;
mf.SequenceOrder = mpq.SequenceOrder;
db.MeetingPollingQuestions.Add(mf);
var MeetingPollingPartList = new List<EFModel.MeetingPollingPart>();
foreach (var p in mpq.MeetingPollingParts)
{
var mfParts = new EFModel.MeetingPollingPart();
mfParts.MeetingPollingQuestionId = mf.MeetingPollingQuestionId;
mfParts.Type = p.Type;
MeetingPollingPartList.Add(mfParts);
}
db.MeetingPollingParts.AddRange(MeetingPollingPartList);
db.SaveChanges();
dbTran.Commit();
This is the error I get:
Problem in mapping fragments starting at line 4481:No mapping specified for properties MeetingPollingPart.MeetingPollingQuestionMeetingPollingQuestionId, MeetingPollingPart.MeetingPollingQuestionMeetingPollingQuestionId1 in Set MeetingPollingParts.
An entity with key (PK) will not round-trip
Updated with Include getting error MeetingPollings not include MeetingPollingParts
var meetingPolling = db.MeetingPollings
.Include(x => x.MeetingPollingQuestions)
.Include(x => x.MeetingPollingParts)
.Single(x => x.MeetingPollingId = =mpq.MeetingPollingId);
EFModel
namespace Repository.EFModel
{
using System;
using System.Collections.Generic;
public partial class MeetingPolling
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public MeetingPolling()
{
this.MeetingPollingQuestions = new HashSet<MeetingPollingQuestion>();
}
public int MeetingPollingId { get; set; }
public Nullable<int> MeetingId { get; set; }
public Nullable<System.DateTime> StartDate { get; set; }
public Nullable<System.DateTime> EndDate { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<MeetingPollingQuestion> MeetingPollingQuestions { get; set; }
}
}
namespace Repository.EFModel
{
using System;
using System.Collections.Generic;
public partial class MeetingPollingQuestion
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public MeetingPollingQuestion()
{
this.MeetingPollingParts = new HashSet<MeetingPollingPart>();
}
public int MeetingPollingQuestionId { get; set; }
public string MeetingPollingQuestionType { get; set; }
public Nullable<int> MeetingPollingId { get; set; }
public Nullable<int> SequenceOrder { get; set; }
public int MeetingPollingMeetingPollingId { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<MeetingPollingPart> MeetingPollingParts { get; set; }
public virtual MeetingPolling MeetingPolling { get; set; }
}
}
namespace Repository.EFModel
{
using System;
using System.Collections.Generic;
public partial class MeetingPollingPart
{
public int MeetingPollingParts { get; set; }
public string Type { get; set; }
public Nullable<int> MeetingPollingQuestionId { get; set; }
public int MeetingPollingQuestionMeetingPollingQuestionId { get; set; }
public virtual MeetingPollingQuestion MeetingPollingQuestion { get; set; }
}
}
UnitTest
MeetingPollingQuestion mpq = new MeetingPollingQuestion();
mpq.MeetingPollingId = 22;
mpq.MeetingPollingQuestionType = "MultipleChoice";
mpq.SequenceOrder = 1;
mpq.MeetingPollingParts = new List<MeetingPollingParts>();
MeetingPollingParts mpp1 = new MeetingPollingParts();
mpp1.Type = "Image";
mpp1.MeetingPollingPartsValues = new List<MeetingPollingPartsValues>();
MeetingPollingPartsValues mppv1 = new MeetingPollingPartsValues();
mppv1.FileManagerId = 500;
mpp1.MeetingPollingPartsValues.Add(mppv1);
mpq.MeetingPollingParts.Add(mpp1);
MeetingService ms = new MeetingService();
var r = ms.SaveMeetingPollingQuestion(mpq);
