Netcore mvc efcore simple framework construction + addition, deletion, modification and query

Netcore mvc efcore simple framework construction + addition, deletion, modification and query

Netcore mvc efcore simple framework construction + addition, deletion, modification and query The database used in this example is mysql; .net core framework, version (sdk) is 3.1. One: Create a net core version of mvc Target framework selection net core3.1 2: After the project is created, first install the nuget package you will use today (the downloaded package should preferably be version 3.1) Microsoft.EntityFrameworkCore; Microsoft.EntityFrameworkCore.Design; Microsoft.EntityFrameworkCore.Tools; Pomelo.EntityFrameworkCore.MySql; For example: (You can manually install using the nuget interface, or you can write statement installation) Three: Overall configuration 1. The database connection is in appsettings.json //Connect to database “AppConfig”: { “AesKey”: “11*222sdf52sf2f2fsdf/.*222,ssddd”, “DbConn span>”: “Server=localhost;port=3306;database=user;uid=root;pwd=root;Convert Zero Datetime=True; ” } 2. Create a class: AppConfig public classAppConfig { /// /// Aes key /// public string AesKey { get; set; } /// /// Database connection string /// public string DbConn { get; set; } } 3. Add a class: NetcoremvcDbcontext as the context and inherit: DbContext class public class NetcoremvcDbcontext : DbContext { private string span> _connectionString; public NetcoremvcDbcontext(IOptionsSnapshot options) { _connectionString = options.Value.DbConn; } protected override voidOnConfiguring(DbContextOptionsBuilder optionsBuilder) { var connectionString = _connectionString ; //Connect to the database UseMySql keyword //MaxBatchSize one An integer value indicating the maximum number of pages that will…

MongoDB eight-day course: Detailed explanation on addition, deletion, checking and modification on the second day

MongoDB eight-day course: Detailed explanation on addition, deletion, checking and modification on the second day

​​ After reading the previous article, I believe everyone will know how to open mongodb. This article will explain in detail the addition, deletion, checking and modification. First, when we use the same method as the previous article to open mongodb, suddenly I was dumbfounded. I wiped it, but it couldn’t be opened. I carefully observed the information of the “underlined area” and found that there was a similar “lock” under the db folder. file” prevents mongodb from opening. The next thing we have to do is to get rid of it. After that, the opening is successful. The management method of mongodb will be shared in a subsequent article. 1: Insert operation ​ As mentioned in the previous article, documents are stored in the “K-V” format. If you are familiar with JSON, I believe that learning mongodb is easy. We know that the Value in JSON may be a “string” or an “array”. It may also be an embedded JSON object. The same method is also suitable for BSON. Common insert operations exist in two forms: “single insert” and “batch insert”. ① Single insertion As mentioned before, the mongo command opens a Javascript shell. So the syntax of js…

nodejs connects to mongodb database to implement addition, deletion, modification and query

Preparation 1. Install mongodb through npm command 2. Install mongodb database CRUD operation Before this, you should have some understanding of the MongoDB database and some of its add, delete, check and modify commands. 1. Add var MOngoClient= require(“mongodb”).MongoClient; var DB_URL = “mongodb://localhost:27017/chm”; function insertData(db) { var devices = db.collection('vip'); var data = {“name”:”node”,”age”:22,”addr”:”nb”,”addTime”:new Date()}; devices.insert(data,function(error, result){ if(error) { console.log('Error:'+ error); }else{ console.log(result.result.n); } db.close(); }); } MongoClient.connect(DB_URL, function(error, db){ console.log('Connection successful!'); insertData(db); }); 2. Find var mOngodb= require('mongodb') var MOngoClient= require('mongodb').MongoClient; var DB_CONN_STR = 'mongodb://localhost:27017/chm'; var selectData = function(db, callback) { //Connect to table var collection = db.collection('vip'); //Query data var whereStr = {“name”:'node'}; collection.find(whereStr,function(error, cursor){ cursor.each(function(error,doc){ if(doc){ //console.log(doc); if (doc.addTime) { console.log(“addTime: “+doc.addTime); } } }); }); } MongoClient.connect(DB_CONN_STR, function(err, db) { console.log(“Connection successful!”); selectData(db, function(result) { console.log(result); db.close(); }); }); 3. Update var MOngoClient= require(“mongodb”).MongoClient; var DB_URL = “mongodb://localhost:27017/chm”; MongoClient.connect(DB_URL, function(error, db){ console.log(“Connection successful!”); updateData(db); }); function updateData(db) { var devices = db.collection('vip'); var whereData = {“name”:”node”} var updateDat = {$set: {“age”:26}}; //If $set is not used, replace the entire data devices.update(whereData, updateDat, function(error, result){ if (error) { console.log('Error:'+ error); }else{ console.log(result); } db.close(); }); } 4. Delete var MOngoClient= require('mongodb').MongoClient; var DB_URL = “mongodb://localhost:27017/chm”; MongoClient.connect(DB_URL, function(error,…

Mongodb database creation, switching, deletion

Mongodb is the most relational database in NoSQL. Single table operations are basically similar to relational databases. Mongodb is relatively easy to learn and use. Record the process of learning and using mongodb in several periods. I won’t talk about mongodb installation, please refer to: centos yum installation mongodb and php extension 1. Create, switch, delete data Mongodb is the most relational database in NoSQL. Single table operations are basically similar to relational databases. Mongodb is relatively easy to learn and use. Record the process of learning and using mongodb in several periods. I won’t talk about mongodb installation. Please refer to: centos yum installation of mongodb and php extension 1. Create, switch, delete database [root@localhost zhangy]# mongo MongoDB shell version: 2.4.6 connecting to: tank > use test //Create or switch database switched to db test > db.dropDatabase() //Delete database { “dropped” : “test”, “ok” : 1 } 2. PHP creates, switches, and deletes databases 1, Switch database $mOngo= new Mongo(); $db = $mongo->selectDB(‘test’); //Switch database 2, Create database $mOngo= new Mongo(); $db = $mongo->selectDB(‘test’); $users = $db->createCollection(“users”); $alldb = $mongo->listDBs(); //List all databases print_r($alldb); //You can see that the db was created successfully It should be noted here that…

MongoDB’s addition, deletion, modification query-mysql tutorial

This article is a few notes on learning mongodb. It mainly introduces the simplest addition, deletion and modification operations. If you are a beginner, look at the API and see if there are any mistakes. I hope you can correct them: (use the official driver) 1. Add and add operations It is the simplest, just construct bsonDcument and insert it: Method 1, construct directly: MongoServer dbserver = new MongoClient(connectionStr) This article is a few notes on learning mongodb. It mainly introduces the simplest addition, deletion and modification operations. If you are a beginner, look at the API and see if there are any mistakes. I hope you can correct them: (use the official driver) 1.increase The easiest way to add an operation is to construct a bsonDcument and insert it: Method 1, direct construction: MongoServer dbserver = new MongoClient(connectionStr).GetServer(); MongoDatabase db = dbserver.GetDatabase(dbName); MongoCollection collection = db.GetCollection(collectionName); dbserver.Connect(); BsonDocument doc = new BsonDocument(); doc[“Age”] = Int32.Parse(txt_Age.Text); doc[“Name”] = txt_Name.Text; doc[“Num”] = txt_Num.Text; doc[“Introduction”] = txt_Introduction.Text; collection.Insert(doc); Method 2, through entity construction: 1 var student = new Student 2 { 3 Age = Int32.Parse(txt_Age.Text), 4 Name = txt_Name.Text, 5 Num = txt_Num.Text, 6 Introduction = txt_Introduction.Text 7}; 8 9 collection.Insert(student); 2.Delete…

MongoDB (6) java operation mongodb addition, deletion, modification and query

We already know the code of Java operating mysql database very well, such as addition, deletion, modification and query. Java also performs similar operations on mongodb database. First, connect to the database, and then perform operations. First we enter the admin database, and then create our own database testMongoDb. After entering the admin database, we can directly enter testMongoDb, because users can We already know the code of Java operating mysql database very well, such as adding, deleting, modifying and checking. Java also performs similar operations on mongodb database. The database connection is first, and then the operation is performed. First we enter the admin database, and then create our own database testMongoDb. After entering the admin database, we can directly enter testMongoDb, because the user can enter the system database, which is the super administrator. After use testMongoDb, set the user for the database name and password, db.addUser('root','root'). In this way, we can connect to the database in the program and implement addition, deletion, modification and query. The code is as follows. The code is as follows: package com.mkyong.core; import java.net.UnknownHostException; import java.util.Date; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.Mongo; import com.mongodb.MongoException; /** * Java +…

Mongodb basic addition, deletion, modification and query-mysql tutorial

To learn a database, the first thing you need to know is how to connect to the database, how to perform basic additions, deletions, modifications and queries, and you can learn other advanced functions slowly. The following mainly explains the basic addition, deletion, modification and query of mogodb 1. Create a database: use mkyongdb (jump to this database if there is one, create and jump if not) Display all databases: show dbs 2. Create a collection ( To learn a database, the first thing you need to know is how to connect to the database, how to perform basic additions, deletions, modifications and queries, and you can learn other advanced functions slowly. The following mainly explains the basic addition, deletion, modification and query of mogodb 1. Create a database: use mkyongdb (if there is one, jump to this database, if not, create and jump) Show all databases: show dbs 2. Create a collection (equivalent to a table in a relational database): Collection operations: (1) Insert data db.users.insert({‘name’:’xumingxiang’,’sex’:’man’}) creates a collection of users Show all collections under the current database: show collections Display all data documents under the users collection: db.users.find() Display the number of records in the collection: db.users.count() (2)…

Basic tutorial on operating MongoDB in PHP (connection, new addition, modification, deletion, query)_PHP tutorial

The code is as follows: //Connect localhost:27017$cOnn= new Mongo(); //Default port for connecting to the remote host$cOnn= new Mongo(‘test.com’); //Connect to the remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has a username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Specify the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//Delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find one$user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close(); http://www.bkjia.com/PHPjc/745824.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/745824.htmlTechArticle The code is as follows: //Connect to localhost:27017 $cOnn= new Mongo(); //Connect to the default port of the remote host $cOnn= new Mongo(‘test.com’); //Connect to the remote host 22011 port $cOnn = new…

PHP simple method to operate MongoDB (installation, addition, deletion, modification and query), mongodb addition and deletion_PHP tutorial

PHP simple method to operate MongoDB (installation, addition, deletion, modification and query), mongodb addition and deletion_PHP tutorial

How to simply operate MongoDB with PHP (installation, addition, deletion, modification and query), add and delete mongodb This article describes the simple method of operating MongoDB with PHP. Share it with everyone for your reference, the details are as follows: If PHP operates MongoDB, first download the MongoDB expansion package from the Internet, https://github.com/mongodb/mongo-php-driver/downloads, and select the corresponding expansion package. I downloaded this and decompressed it. VC6 is suitable for apache, VC9 is suitable for IIS, and ts (thread safe) means that PHP runs in the form of a module. Then put the php_mongo.dll in the ext folder in PHP, then add extension=php_mongo.dll to PHP.INI and restart apache. Now the PHP extension MongoDB package is installed. For information on querying some MongoDB functions, please refer to the manual http://us.php.net/manual/en/class.mongocollection.php PHPDataBase; $collection = $db->PHPCollection; /*——————————– * delete *——————————– $collection->remove(array(“name” => “xixi111”)); */ /*——————————— * insert *——————————– for($i = 0;$i “xixi”.$i,”email” => “673048143_”.$i.”@qq.com”,”age” => $i*1+20); $collection->insert($data); } */ /*———————————- * Find *——————————– $res = $collection->find(array(“age” => array(‘$gt’ => 25,’$lt’ => 40)),array(“name” => true)); foreach($res as $v) { print_r($v); } */ /*———————————- * renew *——————————– $collection->update(array(“age” =>22),array(‘$set’ => array(“name” => “demoxixi”))); */ ?> Readers who are interested in more PHP-related content can check…

Basic tutorial on operating MongoDB in PHP (connection, addition, modification, deletion, query)_PHP

MongoDB The code is as follows://Connect localhost:27017$cOnn= new Mongo(); //Default port for connecting to the remote host$cOnn= new Mongo(‘test.com’); //Connect to the remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has a username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Specify the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//Delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find one$user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close();

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索