I'm making an API with mongo db, after a while of testing, I'm trying to make some calls using linq. So I'm having the following error:
Serializer for ABSRotas.Routing.Entities.Models.Integration does not have a member named RuleActions.
I think it might be something with the mapping, but this error only occurs when I try to make calls using linq.
My calls to mongo are generic, here is the query:
public async Task<IQueryable<TEntity>> Query<TEntity>(Expression<Func<TEntity, bool>> queryExpression)
where TEntity : Entity, IAggregateRoot
{
var database = ConnectToDatabase();
var collection = database.GetCollection<TEntity>(GetCollectionName(typeof(TEntity)));
var query = await collection.FindAsync(queryExpression);
return query.ToList().AsQueryable(); // TODO: medir desempenho de query
}
My call with the repository:
private async Task<List<LineBoardingIntegrations>> GetIntegrations(List<List<LineBoarding>> lineCombinations)
{
var possibleIntegrationsByCombination = new List<LineBoardingIntegrations>();
var maxCount = 0;
var minCount = 999;
foreach (var comb in lineCombinations)
{
// Here my query
var existingIntegrations = await _unitOfWork.Repository<Integration>()
.Query(i => i.Status && i.RuleActions.Count == comb.Count);
existingIntegrations = GetPossibleIntegrations(existingIntegrations, ref maxCount, ref minCount, comb);
if (existingIntegrations.Any())
{
possibleIntegrationsByCombination.Add(new LineBoardingIntegrations()
{
Integrations = existingIntegrations.ToList(),
LineBoardings = comb,
GeneratedCounts = new List<int>()
});
}
}
}
My model:
using ABSCard.Extensions;
using ABSRotas.Common.Domain;
namespace ABSRotas.Routing.Entities.Models
{
public class Integration : Entity, IAggregateRoot
{
public DateTime CreatedOn { get; private set; }
public Guid CreatedBy { get; private set; }
public bool Status { get; private set; }
public string Name { get; private set; }
private List<RuleAction> _ruleActions;
public IReadOnlyList<RuleAction> RuleActions => _ruleActions;
protected Integration()
{
_ruleActions = new List<RuleAction>();
}
public Integration(Guid createdBy, bool status, string name)
{
CreatedOn = DateTime.Now.ToBrazilianTime();
CreatedBy = createdBy;
Status = status;
Name = name;
_ruleActions = new List<RuleAction>();
Validate();
}
}
}
When i change from IReadOnlyList to List it works perfectly.
The model mapping
using ABSRotas.Common.DataAccess.DatabaseFacades.MongoDb;
using MongoDB.Bson.Serialization;
namespace ABSRotas.Routing.Entities.Models
{
public class IntegrationMapping : IMongoMappings
{
public void Register()
{
BsonClassMap.RegisterClassMap<Integration>(cm =>
{
cm.AutoMap();
cm.MapField("_ruleActions").SetElementName("RuleActions");
cm.MapCreator(i => new Integration(i.CreatedBy, i.Status, i.Name));
});
}
}
}
I hope I explained correctly, if anyone has had this error and wants to help me, I will be extremely grateful!!