11月23号(November 23rd)

一、·FirstOrDefault – 返回集合中的第一个元素(如果没有则返回默认值);不延迟

LastOrDefault – 返回集合中的最后一个元素(如果没有则返回默认值)

·Contains – 判断集合中是否包含有某一元素

ToList – 将集合转换为List<T>集合 Average – 集合应为数字类型集合,求其平均值

List<T>用法. List<T>和List的用法是一模一样的,不同的是,List支持任何类型而List<T>只支持T类型,T是在定义时指定的类型. 如: List<string> list=new List<string>; 这样的话,每个list里的元素都是字符串. 同理, List<int> list=new List<int>; 这样的话,每个list里的元素都是整形. List<T>是一个实现List接口反省集合,分开说的话List理解成一个集合,T就代表一个类型,T可以是任何类型,主要用于强制规范一个集合内存放的数据类型必须一致,这样避免了一些不必要的错误,还可以减少拆,装箱操作,提高程序的运行效率

二、需要注意的是FIND查找的是字符的相对位置,而不是查找值 FIND函数区分大小写,与FIND函数相似的函数是SEARCH find找到数据库中的字段,where根据条件进行查询 add添加数据 remove删除数据

三、EF框架的三种模式

DataBase First 数据库优先, 传统的表驱动方式创建EDM,然后通过EDM生成模型和数据层代码。除生成实体模型和自跟踪实现模型,还支持生成轻型DbContext。简历理解就是先设计数据库,创建好数据库映射成对象和上下文。

Model First 模型优先,先创建EDM模型,再生成DDL数据库脚本和模型和数据层代码。除生成实体模型和自跟踪实现模型,支持生成轻型DbContext。简单理解就是设计EDM模型然后生成到数据库和创建对象和上下文。

CodeFirst 代码优先,手动创建POCO模型,数据层DbContext及映射关系,通过Database.SetInitializer生成数据库,这种方式较灵活,但是需要手动定义实体模型和关系映射。简单理解就是自己写好实体对象和映射关系,最后通过命令生成到数据库中去。

四、BaseRepository<T> where T

建一个公共类,让使用到类都去继承公共类,T表示的是泛型,使用的类去填入相应的表名,whereT:class类名

为什么要用泛型类目的很明确就是为了适配不同的模型参数

转化条件为表达式 那么处理一个方法来接受条件 返回表达式,条件可以按照自己的模式去设置

————————

1、 · firstordefault – returns the first element in the set (if not, the default value is returned); No delay

Lastordefault – returns the last element in the collection (default if none)

·Contains – determines whether an element is included in the collection

Tolist – Convert set to list & lt; T> aggregate   Average – the set should be of numeric type, average it

List< T> Usage. List & lt; T> The usage of List as like as two peas is different, and List is different from List&lt. T> Only T type is supported. T is the type specified during definition. For example: List & lt; string> list=new List< string>; In this way, the elements in each list are strings. Similarly, list & lt; int> list=new List< int>; In this case, the elements in each list are shaped. List & lt; T> It is a reflection set that implements the list interface. If you say it separately, list is understood as a set, T represents a type, and t can be any type. It is mainly used to enforce that the data types stored in a set must be consistent, so as to avoid some unnecessary errors, reduce disassembly and packing operations, and improve the operation efficiency of the program

2、 It should be noted that find finds the < strong > relative position of characters < / strong >, not the search value   The find function is case sensitive. A function similar to the find function is search find to find the fields in the database, where to query according to the conditions, add add data, remove delete data

3、 < strong > three modes of EF framework < / strong >

DataBase First   Database first, the traditional table driven method creates EDM, and then generates model and data layer code through EDM. In addition to generating entity model and self tracking implementation model, it also supports the generation of lightweight dbcontext. Resume understanding is to design the database first, create a good database, and map it into objects and contexts.

Model First   Model first, create EDM model first, and then generate DDL database script, model and data layer code. In addition to generating entity model and self tracking implementation model, it supports the generation of lightweight dbcontext. The simple understanding is to design the EDM model, then generate it into the database and create objects and contexts.

CodeFirst   Code first, manually create poco model, data layer dbcontext and mapping relationship, and generate database through database.setinitializer. This method is flexible, but you need to manually define entity model and relationship mapping. The simple understanding is to write entity objects and mapping relationships by yourself, and finally generate them into the database through commands.

四、BaseRepository<T> where T

Create a public class and let all classes inherit the public class. T means generic. Fill in the corresponding table name of the class used. Where t: class name

The reason why generic categories are used is very clear in order to adapt to different model parameters

If the condition is converted to an expression, a method is processed to accept the condition and return the expression. The condition can be set according to its own mode