节点js和代码优先 [英] Node js and Code First
本文介绍了节点js和代码优先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用Code First方法开发了Entity Framework。现在,我正在学习Node.js,我想知道是否有一种方法可以使用Node.js和某些诽谤性的方法进行相同的代码优先方法?我正在考虑将MySql用作数据库。
I've worked on Entity Framework with Code First approach. Now I am learning Node.js I wonder is there a way to make the same code first approach using Node.js and some libraly? I am thinking of using MySql as database.
推荐答案
您可以查看序列化。主页中的用法示例(我添加了与代码优先有关的注释):
You can look into Sequelize. Example of usage from the home page (I added comments to relate to Code First):
var Sequelize = require('sequelize');
// define your "context"
var sequelize = new Sequelize('database', 'username', 'password');
// define your "entities"
var User = sequelize.define('user', {
username: Sequelize.STRING,
birthday: Sequelize.DATE
});
// use them
sequelize.sync().then(function() {
return User.create({
username: 'janedoe',
birthday: new Date(1980, 6, 20)
});
}).then(function(jane) {
console.log(jane.get({
plain: true
}));
});
这篇关于节点js和代码优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文