Linq语句

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().Add(instance);
_context.Set().AddRange(instance);

_context.Set().Remove(EntityModel);
_context.Set().RemoveRange(instance);

_context.Set().Attach(entity);

Linq语句_第1张图片
image.png

https://blog.csdn.net/itmaxin/article/details/47662151


_context.Set().Where(predicate);

linq

#常用linq关键字
_context.Set().
            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(this IQueryable source, Expression> predicate);
        public static bool Any(this IQueryable source, Expression> predicate);
        public static IQueryable AsQueryable(this IEnumerable source); 
        public static decimal? Average(this IQueryable source);
    ....省略
    }

DBset Queryable
API + LINQ API 扩展方法

image.png

linq和 Entity Framework 都又 Queryable

你可能感兴趣的:(Linq语句)