select from list c#
Using System.Linq;
list.where(predicate);
list.select(predicate);
select from list c#
Using System.Linq;
list.where(predicate);
list.select(predicate);
select single item from list c#
using (var db = new ApplicationDbContext())
{
///itemModel is the model with gets & sets
var file = db.Table
.Where(x => x.Id == id)
.Select( x => new itemModel
{
itemTest = x.itemTest,
}).ToList();
///creating a new model
ModelList ML = new ModelList();
///creating a new list
ML.ViewModelList = new List<ViewModel>();
///getting each item from list
foreach(var item in file)
{
ViewModel img = new ViewModel();
img.itemTest = item.itemTest;
ML.ViewModelList.Add(img);
}
///selecting the last item from the list
var singleitem = ML.ViewModelList.Select(x => x.itemTest).LastOrDefault();
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us