markrendle / Simple.Data

A light-weight, dynamic data access component for C# 4.0
MIT License
1.33k stars 303 forks source link

InMemoryAdapter FindBy does not find records #360

Closed divmgl closed 9 years ago

divmgl commented 9 years ago

When using the InMemoryAdapter, executing a FindBy with multiple conditions will not work.

Database.UseMockAdapter(new InMemoryAdapter());
Database db = Database.Open();

var Accounts = db["Accounts"];
Accounts.Insert(new {
    Id: 1,
    Active: true
});

var all = Accounts.All();
// Returns one record

var account = Accounts.FindBy(Id: 1, Active: true);
// Returns null

This is leading to some serious problems doing proper TDD. I will investigate to see what could be causing this issue.

divmgl commented 9 years ago

I have been able to confirm that using this is only occurring when using a dynamic object.

Accounts.Insert(new Account {
    Id: 1,
    Active: true
});

var account = Accounts.FindBy(Id: 1, Active: true); 
// Returns a record

Accounts.Insert(new {
    Id: 2,
    Active: true
});

var nullAccount = Accounts.FindBy(Id: 2, Active: true); 
// Returns null
divmgl commented 9 years ago

I have been able to get more information on this problem.

When using an InMemoryAdapter, the FindBy method does not understand different numerical types that are equal in value. For instance, a long type with a value of 0 is not the same as a int type with a value of 0.

Not sure yet if this is good or bad, the issue still persists with dynamic objects.