var result = students.Where(x => x.Sex.Equals("男") && x.Age == 23).OrderByDescending(x =>
x.Id);
from s in students
where s.name.contains("li")
select new{
studentname=s.name
studentage=s.age
}
students.where(s=>s.name.contains("li")).select(s=>new{
studentname=s.name
studentage=s.age
})
Entity Framework
增
_context.Set<TModel>().Add(instance);
_context.Set<TModel>().AddRange(instance);
删
_context.Set<TModel>().Remove(EntityModel);
_context.Set<TModel>().RemoveRange(instance);
改
_context.Set<TModel>().Attach(entity);
image.png
https://blog.csdn.net/itmaxin/article/details/47662151
查
_context.Set<TModel>().Where(predicate);
linq
#常用linq关键字
_context.Set<TModel>().
Where(predicate);
Select(x => new Line()
{
ID = x.metroId,
Name = x.metroName
});
OrderBy(x => x.layerOrder);
FirstOrDefault();
join
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace System.Linq
{
public static class Queryable
{
public static bool All<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate);
public static bool Any<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate);
public static IQueryable<TElement> AsQueryable<TElement>(this IEnumerable<TElement> source);
public static decimal? Average(this IQueryable<decimal?> source);
....省略
}
DBset Queryable
API + LINQ API 扩展方法
image.png
linq和 Entity Framework 都又 Queryable









网友评论