As discussed from our previous post, MongoDB is pretty good if we can work it in int's unique way. So, to do all of the work, we need to have a propert DB layer. Let's first look at how we can connect and then do a sample select.
Using above code, you can connect to the locally installed DB server get a list of records which can be converted into a list of entity.
Lets see how this is used.
The Person is an entity which we use in the collection. The bllPerson is a class that handles DB calls. So it gets all the people saved under Person collection in the Database.
Try it and next time lets talk about Updated and Delete method.
Happy coding.
var client = new MongoClient("mongodb://localhost:27017");
mongoDatabase = client.GetDatabase("TemplateManager");
public List<T> Select<T>(string TableName, string SelectColumnName, BsonValue WhereValue)
{
var collection = mongoDatabase.GetCollection<T>(TableName);
var filter = Builders<T>.Filter.Eq(SelectColumnName, WhereValue);
return collection.Find(filter).ToList();
}
Using above code, you can connect to the locally installed DB server get a list of records which can be converted into a list of entity.
Lets see how this is used.
List<Person> personList = new bllPerson().Select();
The Person is an entity which we use in the collection. The bllPerson is a class that handles DB calls. So it gets all the people saved under Person collection in the Database.
Try it and next time lets talk about Updated and Delete method.
Happy coding.
No comments:
Post a Comment