1

i use a database which is named LiteDB. this is a Nosql and free database for Dot-net. when i access my tables it returns a collection named 'LiteCollection'. I want to iterate over it. but it doesn't implement Getenumerator() method. and there is not any other indexing on it. i want to create an Ienumerable to set in on my Raddropdownlist(which is the name of Combo box in Telerik components). is there any way to do this?

using (var db = new LiteDatabase(@"MyData.db"))
        {

            // Get cookie collection
            var Cookies2 = db.GetCollection<Cookie>("Cookies2");
            Cookies2.EnsureIndex(x => x.Id);

            foreach (var item in Cookies2) //it couldn't be done
            {

            }
            // or 
            for (int i = 0; i < Cookies2.Count(); i++)
            {
                temp.Add(Cookies2.??)
            }


        }
Hamed Sanaei
  • 121
  • 13

2 Answers2

1

Oops i find a simple way. Litecollection has a method which returns all objects. the FindAll() method do this.

          foreach (var item in Cookies2.FindAll())
            {

            }
Hamed Sanaei
  • 121
  • 13
1

I found this solution......

using (var db = new LiteDatabase("RouletteDB.db"))
{
    IEnumerable<Test> tests = db.GetCollection<Test>("tests").FindAll().ToList();
    return View(tests);
}
Dharman
  • 30,962
  • 25
  • 85
  • 135