It is called projection and simply translates to SELECT column1, column2, ...in SQL:
var result = db.Articles
.Select(a => new
{
Date = a.Date,
Title = a.Title
})
.ToList();
Instead a => new { ... }(creates a list of "anonymous" objects) you can also use a named helper class (or "view model"): a => new MyViewModel { ... }that contains only the selected properties (but you cannot use it a => new Article { ... }as an entity itself).
AsNoTracking(), , .
Contains Where, :
var date = DateTime.Now.AddYears(-1);
var result = db.Articles
.Where(a => date <= a.Date)
.Select(a => new
{
Date = a.Date,
Title = a.Title
})
.ToList();
, . Where SQL Where, ( , SQL-, ..). .
Edit
:
IEnumerable<T>.Contains(T t) string.Contains(string subString). , , Contains. "keyword" , Contains:
string keyword = "Entity Framework";
var result = db.Articles
.Where(a => a.Body.Contains(keyword))
.Select(a => new
{
Date = a.Date,
Title = a.Title
})
.ToList();
WHERE Body like N'%Entity Framework%' SQL. Contains Contains.