M
M
Michael Vasyukov2017-11-02 00:45:56
Database
Michael Vasyukov, 2017-11-02 00:45:56

Selecting multiple data in LiteDB database, C#?

Good day to all! In my project, I use a database like LiteDB, everything seems to be working fine, but I can’t figure out one thing! How to make a selection from this database by several values? I know how to filter data by only one value, it's done like this:

using (var db = new LiteDatabase(@"MyData.db"))
            {
                var col = db.GetCollection<User>("User");

                var result = col.Find(x => x.Login.StartsWith(LoginTB.Text));
            }

here I am looking for all the lines that match the "login", and I need to find the line in which both the login and password match my data. Where to enter the second condition?
PS Thank you all!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniel, 2017-11-02
@programmer_developer

var result = col.Find(x => x.Login.StartsWith(LoginTB.Text));

If you also do a password check, then you need a complete similarity of the login and password. Something like this:
var result = col.Find(x => x.Login == LoginTB.Text && x.Password == PwdTB.Text);
And yes, do not store the password in the database in an unprotected form, use cryptography to encrypt the password. Or store only its hash, and then compare.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question