Linq语句

2019-08-19  本文已影响0人  丶End

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

上一篇 下一篇

猜你喜欢

热点阅读