我在 EF 上有一个这样的后端属性
public partial class PatientSurveyQuestion
{
public PatientSurveyQuestion()
{
this.PatientSurveyQuestionAnswers = new HashSet<PatientSurveyQuestionAnswer>();
this.PatientSurveyReplies = new HashSet<PatientSurveyReply>();
}
public int QuestionID { get; set; }
public string QuestionText { get; set; }
public Nullable<int> PointID { get; set; }
public Nullable<int> QuestionType { get; set; }
public virtual PatientSurveyPoint PatientSurveyPoint { get; set; }
public virtual ICollection<PatientSurveyQuestionAnswer> PatientSurveyQuestionAnswers { get; set; }
public virtual ICollection<PatientSurveyReply> PatientSurveyReplies { get; set; }
}
public partial class PatientSurveyQuestionAnswer
{
public int QuestionID { get; set; }
public int AnswerID { get; set; }
public Nullable<System.DateTime> DateCreayed { get; set; }
public virtual PatientSurveyAnswer PatientSurveyAnswer { get; set; }
public virtual PatientSurveyQuestion PatientSurveyQuestion { get; set; }
}
和一个加入班
public class PatientQS
{
public PatientSurveyQuestion Question { get; set; }
public List<PatientSurveyAnswer> Answers { get; set; }
}
我也有相同的类,没有 WFC 的引用和虚函数
[DataContract]
public class Question
{
[DataMember]
public int QuestionID { get; set; }
[DataMember]
public string QuestionText { get; set; }
[DataMember]
public Nullable<int> PointID { get; set; }
[DataMember]
public Nullable<int> QuestionType { get; set; }
}
[DataContract]
public class Answers
{
[DataMember]
public int AnswerID { get; set; }
[DataMember]
public string Answer { get; set; }
}
[DataContract]
public class QuestionsAnswers
{
[DataMember]
public Question Question { get; set; }
[DataMember]
public List<Answers> Answers{ get; set; }
}
然后我运行查询以获取数据并使用 autopmaper
var quesans = (from c in db.PatientSurveyQuestions
from v in db.PatientSurveyQuestionAnswers
where c.QuestionID == v.QuestionID && c.PointID == pointID
select new {c, ans=c.PatientSurveyQuestionAnswers.Select(n=>n.PatientSurveyAnswer)}).ToList().Select(c => new PatientQS { Question = c.c, Answers = c.ans.ToList() }).ToList();
Mapper.CreateMap<PatientSurveyAnswer, Answers>();
Mapper.CreateMap<PatientQS, QuestionsAnswers>().ForMember(c=>c.Answers, m=>m.MapFrom(
q=>Mapper.Map<List<PatientSurveyAnswer>, List<Answers>>(q.Answers)
));
QuestionsAnswers q2 = Mapper.Map<QuestionsAnswers>(quesans);
但是自动映射器给了我一个错误
缺少类型映射配置或不支持的映射。
映射类型:列表
1 -> QuestionsAnswers System.Collections.Generic.List
1[[PatientService1.PROP.PatientQS, PatientService1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> PatientService1.PROP.QuestionsAnswers目标路径: QuestionsAnswers
源值:System.Collections.Generic.List`1[PatientService1.PROP.PatientQS]
我做错了什么还是真的不支持?