【发布时间】:2017-01-23 20:22:02
【问题描述】:
有人可以帮助我吗?我花了很多时间来解决这个问题,什么都没有
这是我的实体和帮助对象:
public class Course
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId Id { get; set; }
[BsonRepresentation(BsonType.ObjectId)]
[BsonElement("_etag")]
public ObjectId Etag { get; set; }
[BsonElement("group")]
public KeyValueEntity<string> Group { get; set; }
[BsonElement("values")]
public GroupValuesCourse[] Values { get; set; }
}
public class KeyValueEntity<T>
{
[BsonElement("key")]
[JsonProperty("key")]
public string Key { get; set; }
[BsonElement("value")]
[JsonProperty("value")]
public T Value { get; set; }
public override string ToString()
{
return Value?.ToString();
}
}
public class GroupValuesCourse
{
[BsonElement("group")]
public KeyValueEntity<string> GroupKeys { get; set; }
[BsonElement("values")]
public KeyValueEntity<string>[] ValueKeys { get; set; }
}
还有我的存储库
public async Task<IEnumerable<KeyValueEntity<string>>> GetAllForGroupAsync(string groupName, string subGroupName)
{
return await mongoDbContext.MongoDataBase.GetCollection<Course>("courses").AsQueryable()
.Where(courseGroup => courseGroup.Group.Value == groupName)
.SelectMany(courseGroups => courseGroups.Values)
.Where(subgroup => subgroup.GroupKeys.Value == subGroupName)
.SelectMany(groups => groups.ValueKeys)
.OrderBy(value => value.Value)
.ToListAsync();
}
执行后告诉我:System.FormatException: Element 'group' does not match any field or property of class Gillie.JobCenter.Domain.KeyValueEntity`1[[System.String, System.Private.CoreLib, Version =4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e]]。 但我确信映射是正确的。有人可以帮我找出错误吗?
【问题讨论】:
-
请不要破坏您的帖子。
-
@DimaGrigoriev 不,你没有。通过在 Stack Overflow 上发布此内容,您同意公开许可此内容,从而使您在此帖子上的声明无效。
-
不,你没有。有些用户花时间和精力写出体面的答案。
-
您可以随时要求将此帖子与您的帐户解除关联;为此使用Contact Us 表单。