有人能解釋這個錯誤的含義嗎?我以前使用過automapper,但從未發生過這種錯誤。缺少類型映射配置或不支持的映射
錯誤
服務器遇到錯誤處理請求。異常消息是'丟失類型映射配置或不支持的映射。映射類型:Char - > QuestionDto System.Char - > CollectiveDistributedPolling.QuestionDto目標路徑:QuestionDto.Question1.Question1.Question10 [0]源值:R'。
Service1.svc.cs
public Service1() {
Mapper.CreateMap<Question, QuestionDto>();
Mapper.CreateMap<QuestionDto, Question>();
}
private Question MapToQuestion(QuestionDto q)
{
return Mapper.Map<QuestionDto, Question>(q);
}
private QuestionDto MapToQuestionDto(Question q) <<< EXCEPTION GETS THROWN HERE
{
return Mapper.Map<Question, QuestionDto>(q);
}
public QuestionDto ThrowQuestion(string user)
{
return MapToQuestionDto(Database.GetInstance().ThrowQuestion(user));
}
IService1.cs
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
QuestionDto ThrowQuestion(String user);
[DataContract]
public class QuestionDto
{
[DataMember]
public int ID { get; set; }
[DataMember]
public int next { get; set; }
[DataMember]
public String question { get; set; }
[DataMember]
public ICollection<QuestionDto> QuestionPhrase { get; set; }
[DataMember]
public QuestionDto Next{ get; set; }
[DataMember]
public ICollection<QuestionAnswerDto> QuestionAnswer { get; set; }
[DataMember]
public ICollection<UserAnswerDto> UserAnswer { get; set; }
}
Question.cs
public partial class Question
{
public Question()
{
this.QuestionPhrase = new HashSet<Question>();
this.QuestionAnswer = new HashSet<QuestionAnswer>();
this.UserAnswer = new HashSet<UserAnswer>();
}
public int ID { get; set; }
public string question { get; set; }
public Nullable<int> next { get; set; }
public virtual ICollection<Question> QuestionPhrase { get; set; }
public virtual Question Next { get; set; }
public virtual ICollection<QuestionAnswer> QuestionAnswer { get; set; }
public virtual ICollection<UserAnswer> UserAnswer { get; set; }
}
}
由於d anludwig我可以找出問題所在。它是與
[DataMember]
public QuestionDto Next{ get; set; }
但是,這似乎映射罰款我
請發表您的問題類。 「char」類型的任何一個對象是否有任何屬性? – danludwig
@danludwig發佈了Question類,但沒有字符類型 – David
您可以使用Mapper.DynamicMap <>進行檢查。 –