Skip to content

[BUG] v5.0.4 ILiteCollection.Find() does not work with enum #1589

@hopson-2

Description

@hopson-2

Version
5.0.4/Windows 10/net framework 4.7,2

Describe the bug
the ILiteCollection.Find() method does not appear to work with enum

Code to Reproduce
LINQPad v5.41/C# Program

void Main()
{
	const string databaseFilename = @"C:\temp\litedb_504_test.db";
	using (LiteDB.ILiteDatabase liteDB= new LiteDatabase(databaseFilename))
	{
		ILiteCollection<Customer> collectionCustomer = liteDB.GetCollection<Customer>("Customer");
		liteDB.DropCollection("Customer"); //remove previous test customers from DB
		
		Customer doeJohn = new Customer()
		{
			Name="John Doe"
			, Description = "Test Customer"
			, PaymentMethod = PaymentMethodType.Cash
		};
		Customer doeJane = new Customer()
		{
			Name = "Jane Doe"
			, Description = "Test Customer 2"
			, PaymentMethod = PaymentMethodType.CreditCard
		};

		collectionCustomer.Upsert(doeJohn);
		collectionCustomer.Upsert(doeJane);
		collectionCustomer.EnsureIndex(x => x.Id);
		
		collectionCustomer.Find(x => x.Name=="John Doe").Dump("Find John");
		collectionCustomer.Find(x => x.Name.Contains("Doe")).Dump("Find all Doe");
		collectionCustomer.Find(x => x.PaymentMethod==PaymentMethodType.Cash).Dump("Find all cash with enum does not work");
	}
}

// Define other methods and classes here
public enum PaymentMethodType
{
	None = 0,
	Cash = 1,
	CreditCard = 2
}
public class Customer 
{
	public int Id { get; set; }
	public string Name { get; set; }
	public string Description { get; set; }
	public PaymentMethodType PaymentMethod { get; set; }
}

Expected behavior
collection items with matching enum values should be returned

Screenshots/Stacktrace
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions