Forum Xamarin.Forms

Select all items from local DB having a particular value

SreeeeSreeee INMember ✭✭✭✭✭

I implemented local DB in my project and I am using following code for select all the items from local DB. MyCommunities is my model class.

public List<MyCommunities> GetItems()
    {
        lock (locker)
        {
            return (from i in database.Table<MyCommunities>() select i).ToList();
        }
    }

I am using following code for taking an item from local DB with a particular officename(it only return one item):

public MyCommunities GetItemByOfficename(string office)
    {
        lock (locker)
        {
            return database.Table<MyCommunities>().FirstOrDefault(x => x.Officename == office);
        }
    }

I am trying to select all the items from local DB having a particular userid(It should be a list of Mycommunities). Don't know how to add userid when parsing.

Thanks in advance :)

Best Answer

  • TobyKTobyK GB ✭✭✭
    Accepted Answer
        public List<MyCommunities> GetItemsByUserId(int userId)
        {
            lock (locker)
                {
                        return database.Table<MyCommunities>().Where(x => x.UserId == userId).ToList();
                }
        }
    

Answers

  • TobyKTobyK GBMember ✭✭✭
    Accepted Answer
        public List<MyCommunities> GetItemsByUserId(int userId)
        {
            lock (locker)
                {
                        return database.Table<MyCommunities>().Where(x => x.UserId == userId).ToList();
                }
        }
    
Sign In or Register to comment.