The scenario has recently adjusted the crawler's database architecture and needs to migrate data to MongoDB. We need to implement a new Dao generic class for MongoDB. Okay, let's get started, the problem arises when the delete operation is implemented. Our Delete operation is defined as follows: void Delete (TEntity entity ). TEntity is our generic class. The delete operation that comes with the MongoDB official driver is as follows: // assume that the data model is defined as Articlevar query = Query <Article>. EQ (t => t. id, id); coll. remove (query); the Dao operation interface cannot be modified. Therefore, we must perform the following operations: get the Id value of the entity to construct a lambda expression to get the Id attribute. For example, you can use reflection to get the Id attribute. As for the 1st lambda expressions, you don't know how to create it. Search for information on the Internet and learn that the C # Lambda Expression Tree allows us to process Lambda expressions like processing data (such as reading and modifying data .. This has a direction. I have studied the knowledge of Expression Tree, and finally implemented it after great bumps. The lambda expressions I use are relatively simple and easy to construct. You can see the annotations in the Code. Code: // <summary> /// the Mongodb used, each data model must contain the Id attribute, delete an object using the Id attribute // </summary> /// <param name = "entity"> </param> public void Delete (TEntity entity) {var coll = _ db. getCollection <TEntity> (typeof (TEntity ). name); if (entity = null) {return;} ObjectId id = (ObjectId) typeof (TEntity ). getProperty ("Id "). getValue (entity, null); // construct a lambda expression {t => t. id} // construct the call target t var target = Expression. parameter (typeof (TEntity), "t"); // construct the Expression MemberExpression bodyExp = Expression for the attribute Id of t. property (target, "Id"); // construct a complete lambda Expression <Func <TEntity, ObjectId> selector = Expression. lambda <Func <TEntity, ObjectId> (bodyExp, new [] {target}); // use the statement before generics: Query <Article>. EQ (t => t. id, id); var query = Query <TEntity>. EQ (selector, id); coll. remove (query );}