Unable to determine the serialization information for i => i.Id using interfaces

不想你离开。 提交于 2019-12-05 20:23:26
  1. For

"Unable to determine the serialization information for i => i.Id."

Try to use: nameof().

Builders<T>.Filter.Eq(nameof(IEntity.Id), entity.Id)

2.

...but I'd like to avoid this if possible, as I want to keep my model layer (where IEntity resides) free of any database platform specific references.

My solution for problem like your and similar problems:

public interface IEntity {
    [BsonId]
    string Id { get; set; }

    string IdEntity { get; set; }
}

[BsonIgnoreExtraElements(Inherited = true)]
public abstract class BaseEntity : IEntity 
{
    [BsonRepresentation(BsonType.ObjectId)]
    public virtual string Id { get; set; }

    [BsonIgnoreIfNull]
    public string IdEntity { get; set; }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!