Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hopson-2 opened this issue Mar 23, 2020 · 3 comments
Closed

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

hopson-2 opened this issue Mar 23, 2020 · 3 comments
Labels

Comments

@hopson-2
Copy link

hopson-2 commented Mar 23, 2020

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

@hopson-2 hopson-2 added the bug label Mar 23, 2020
@maxkatz6
Copy link
Contributor

Can you test it with latest master?
I think, it could be duplicate of #1548.

@lbnascimento
Copy link
Collaborator

@hopson-2 I tested your example with master and it works. It was recently fixed and will be present in the next incremental release.

Also, a tip: there's no need to run EnsureIndex over the id field, since the index over the id is always created upon the first insertion and it can't be dropped.

@hopson-2
Copy link
Author

hopson-2 commented Mar 25, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants