comminity-data-odata-linq
comminity-data-odata-linq copied to clipboard
System.InvalidOperationException: 'The entity 'IncomingFileTransaction' does not have a key defined.'
I am using MongoDB.Driver
and trying to apply OData to the IMongoCollection<T>.AsQueryable()
var items = myCollection.Query().OData().Filter("((contains(Name,'2021')))").ToList();
But I am getting this exception
System.InvalidOperationException: 'The entity 'IncomingFileTransaction' does not have a key defined.'
I've tried adding both [Key]
and [BsonId]
to the class, but no luck
public abstract class AggregateRoot
{
[BsonId, Key]
public ObjectId Id { get; set; } = ObjectId.GenerateNewId();
public int ConcurrencyVersion { get; set; }
public DateTime CreatedUtc { get; set; } = DateTime.UtcNow;
public DateTime ModifiedUtc { get; set; } = DateTime.UtcNow;
}
public class IncomingFileTransaction : AggregateRoot
{
public string Name { get; set; }
}
Please tell me this is going to work with MongoDB.Driver!
A bit late but... this only worked for me if I used an int type as the key value. Anything else threw this error even with the [Key] property.
Is there any way to make this package work with string IDs?
I need Guid keys