从 entitycollection 中移除值
Remove value from entitycollection
我需要根据某些值从实体集合中删除实体。
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
}
像这样:
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);
}
我需要根据某些值从实体集合中删除实体。
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
}
像这样:
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);
}