comminity-data-odata-linq icon indicating copy to clipboard operation
comminity-data-odata-linq copied to clipboard

System.InvalidOperationException: 'The entity 'IncomingFileTransaction' does not have a key defined.'

Open mrpmorris opened this issue 4 years ago • 3 comments

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!

mrpmorris avatar Jan 30 '21 20:01 mrpmorris

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.

CREFaulk avatar Aug 09 '21 19:08 CREFaulk

Is there any way to make this package work with string IDs?

vaibhav29498 avatar Nov 12 '21 05:11 vaibhav29498

I need Guid keys

mrpmorris avatar Nov 12 '21 09:11 mrpmorris