0

I need to remove the Entity from the entitycollection based on some values.

EntityCollection users = new EntityCollection();

List<string> UsersList = new List<string>();
UsersList.add("test1")
UsersList.add("test2")
UsersList.add("test3")


foreach (string item in UsersList )
                {
                    string ls = item;
                   // here I need to remove the users (entitycollection) value based on ls
                }
User
  • 1,644
  • 10
  • 40
  • 64
  • I think you should execute it as a query, since doing so required iteration for each entity. – Inbar Barkai Oct 09 '16 at 05:26
  • foreach (string item in UsersList ) { string ls = item; // here I need to remove the users (entitycollection) value based on ls var refer = users.Entities.References.FirstOrDefault(r => r.value == ls); } – User Oct 09 '16 at 05:34
  • If i use the for each state means am getting the following error,'DataCollection' does not contain a definition for 'References' and no extension method 'References' accepting a first argument of type 'DataCollection' could be found (are you missing a using directive or an assembly reference?) – User Oct 09 '16 at 05:35

1 Answers1

1

Something like this:

class User
        {
            public string Name { get; set; }
        }

EntityCollection<User> users = new EntityCollection<User>();
        users.Add(new User() { Name = "test1" });

        List<string> UsersList = new List<string>();
        UsersList.Add("test1");
        UsersList.Add("test2");
        UsersList.Add("test3");


        foreach (string item in UsersList)
        {
            string ls = item;
            var user = users.Where(x => x.Name == ls).FirstOrDefault();
            if(user!=null)
                users.Remove(user); 
        }
H.Gh
  • 306
  • 2
  • 16