MVC中使用EF(1):为ASP.NET MVC程序创建Entity Framework数据模型
Contoso University示例网站演示如何使用Entity Framework 5创建ASP.NET MVC 4应用程序。
Entity Framework有三种处理数据的方式: Database First, Model First, and Code First. 本指南使用代码优先。其它方式请查询资料。
示例程序是为Contoso University建立一个网站。功能包括:学生管理、课程创建、教师分配。 本系列指南逐步讲述如何实现这一网站程序。
本示例程序基于 ASP.NET MVC.如果使用 ASP.NET Web Forms model, 请查看 Model Binding and Web Forms系列指南和 ASP.NET Data Access Content Map.
如有问题,可在这些讨论区提问: ASP.NET Entity Framework forum, the Entity Framework and LINQ to Entities forum, or StackOverflow.com.
(此指南的旧版本请查看 the EF 4.1 / MVC 3 e-book.)
Contoso University 应用程序
本指南将创建一个简单的大学网站.
用户可查看或更新学生、课程、教师的信息,以下是相关截图:
UI风格延续了默认模板的风格,以便更多关注于如何使用Entity Framework。
需求
使用 Visual Studio 2012 or Visual Studio 2012 Express for Web, 可从以下链接获取相关需求软件:
Windows Azure SDK for Visual Studio 2012
If you have Visual Studio installed, the link above will install any missing components. If you don't have Visual Studio, the link will install Visual Studio 2012 Express for Web.
若使用 Visual Studio 2010,需要安装MVC 4 和 SQL Server LocalDB.
创建MVC Web程序
创建程序如下:
选择 Internet Application template.
选择 Razor
Click OK.
设置网站风格
菜单、布局有少许变动.
打开Views\Shared\_Layout.cshtml, 修改如下:黄色为修改后内容.
<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"/><title>@ViewBag.Title - Contoso University</title><linkhref="~/favicon.ico"rel="shortcut icon"type="image/x-icon"/><metaname="viewport"content="width=device-width"/>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head><body><header><divclass="content-wrapper"><divclass="float-left"><pclass="site-title">@Html.ActionLink("Contoso University", "Index", "Home")</p></div><divclass="float-right"><sectionid="login">
@Html.Partial("_LoginPartial")
</section><nav><ulid="menu"><li>@Html.ActionLink("Home", "Index", "Home")</li><li>@Html.ActionLink("About", "About", "Home")</li><li>@Html.ActionLink("Students", "Index", "Student")</li><li>@Html.ActionLink("Courses", "Index", "Course")</li><li>@Html.ActionLink("Instructors", "Index", "Instructor")</li><li>@Html.ActionLink("Departments", "Index", "Department")</li></ul></nav></div></div></header><divid="body">
@RenderSection("featured", required: false)
<sectionclass="content-wrapper main-content clear-fix">
@RenderBody()
</section></div><footer><divclass="content-wrapper"><divclass="float-left"><p>© @DateTime.Now.Year - Contoso University</p></div></div></footer> @Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body></html>
上面做了两点改变:
- 把 "My ASP.NET MVC Application" 和"your logo here" 替换为"Contoso University".
- 添加一些后面用到的超链接
在Views\Home\Index.cshtml, 替换为如下代码:
@{
ViewBag.Title = "Home Page";
}
@section featured {
<sectionclass="featured"><divclass="content-wrapper"><hgroupclass="title"><h1>@ViewBag.Title.</h1><h2>@ViewBag.Message</h2></hgroup></div></section>
}
在 Controllers\HomeController.cs, 把 ViewBag.Message
值替换为 "Welcome to Contoso University!":
publicActionResultIndex(){ViewBag.Message="Welcome to Contoso University";returnView();}
CTRL+F5 运行,界面如下.
创建数据模型
先创建如下三个数据模型:
Student
and Enrollment
实体是一对多关系,, Course
and Enrollment
实体也是一对多关系. 也就是说一个学生可以注册多门课程,一门课程允许多位学生注册。
为每个实体创建对应的类:
Note If you try to compile the project before you finish creating all of these entity classes, you'll get compiler errors.
Student Entity
在Models文件夹创建Student.cs ,代码如下:
usingSystem;usingSystem.Collections.Generic;namespaceContosoUniversity.Models{publicclassStudent{publicintStudentID{get;set;}publicstringLastName{get;set;}publicstringFirstMidName{get;set;}publicDateTimeEnrollmentDate{get;set;}publicvirtualICollection<Enrollment>Enrollments{get;set;}}}
StudentID
属性将成为数据表的主键列。默认Entity Framework将名为ID或者类名ID的属性设为主键。
Enrollments
是一个导航属性。导航属性记录和本实体相关的其它实体。在本例中,Enrollments
属性记录和 Student
属性相关的Enrollment。.如果数据库中某Student记录和
两条Enrollment记录
相关。(这两条记录的 StudentID
外键值等于该Student的StudentID)
,那么Student
实体的 Enrollments
导航属性将包含这两个 Enrollment
实体.
Navigation properties 常定义为virtual
以便发挥Entity Framework的功能,如 lazy loading. (在 Reading Related Data 部分将详细讲述延迟加载).
如果navigation property 包含多记录 (如 many-to-many or one-to-many 关系), 类型最好是列表类型,如 ICollection
.
The Enrollment Entity
在Models文件夹, 创建 Enrollment.cs,代码如下:
namespaceContosoUniversity.Models{publicenumGrade{
A, B, C, D, F
}publicclassEnrollment{publicintEnrollmentID{get;set;}publicintCourseID{get;set;}publicintStudentID{get;set;}publicGrade?Grade{get;set;}publicvirtualCourseCourse{get;set;}publicvirtualStudentStudent{get;set;}}}
Grade类型
后面的问号表示Grade
属性是 nullable.
StudentID
property 是外键, 相应的导航属性是 Student
.一个 Enrollment
实体和一个 Student
实体相关,
CourseID
property 是外键, 相应的导航属性是 Course
.
The Course Entity
In the Models folder, create Course.cs, replacing the existing code with the following code:
usingSystem.Collections.Generic;usingSystem.ComponentModel.DataAnnotations.Schema;namespaceContosoUniversity.Models{publicclassCourse{[DatabaseGenerated(DatabaseGeneratedOption.None)]publicintCourseID{get;set;}publicstringTitle{get;set;}publicintCredits{get;set;}publicvirtualICollection<Enrollment>Enrollments{get;set;}}}
Enrollments
属性是导航属性. A Course
实体对应多个 Enrollment
实体.
下一节再对 [DatabaseGenerated(DatabaseGeneratedOption.None)]
特性进行讲解。 简而言之,此特性表明主键由你赋值而非数据库自动生成。
创建Database Context
将 Entity Framework 功能和给定数据模型相关联的类是 database context class. 此类继承自 System.Data.Entity.DbContext class.代码表明数据模型包含了哪些实体类型.本项目中数据上下文类名为 SchoolContext
.
创建 DAL文件夹 (for Data Access Layer). 在此文件夹创建SchoolContext.cs,代码如下:
usingContosoUniversity.Models;usingSystem.Data.Entity;usingSystem.Data.Entity.ModelConfiguration.Conventions;namespaceContosoUniversity.DAL
{publicclassSchoolContext:DbContext{publicDbSet<Student>Students{get;set;}publicDbSet<Enrollment>Enrollments{get;set;}publicDbSet<Course>Courses{get;set;}protectedoverridevoidOnModelCreating(DbModelBuilder modelBuilder){
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();}}}
代码为每一个实体集合创建 DbSet 属性。. 在Entity Framework,实体集合对应数据表,一个实体对应表中的一条记录。.
modelBuilder.Conventions.Remove
语句阻止表名使用实体的复数形式,如果没有此语句,则生成的数据表分别是 Students
, Courses
, andEnrollments
. 使用此语句,表名将和实体名一样 Student
, Course
, and Enrollment
. 这和编程风格相关,至于是否使用复数取决于你自己。
SQL Server Express LocalDB
LocalDB 是一个轻量级的SQL Server。这里不做翻译介绍。
打开根目录下的 Web.config 文件,在 connectionStrings
处添加连接字符串如下,(注意,如果没有localdb,而使用SQL Server或者Express版本,请修改连接字符串)
<addname="SchoolContext"connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ContosoUniversity;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\ContosoUniversity.mdf"providerName="System.Data.SqlClient"/>
默认Entity Framework寻找和数据上下文类同名的连接字符串 (SchoolContext
for this project). 更多连接字符串信息,请查看 SQL Server Connection Strings for ASP.NET Web Applications.
也可不添加连接字符串,由程序自动生成。但会导致数据库文件没有放在程序的 App_data文件夹下,更多信息请查看 Code First to a New Database.
connectionStrings
集合默认包含一个名为 DefaultConnection的连接字符串,是用来连接
membership database. 这里不会用到。两条连接字符串唯一不同之处是数据库名字不同
设置并执行 Code First Migration
在程序初期,数据模型经常发生变动,每次变动就会导致和数据库不一致。可将Entity Framework配置为变动后自动重建数据库。但在程序使用之后如果发生变动,更希望是更新数据库而非重建(重建导致数据丢失)。 Migrations 功能使得代码优先方式下更新数据库。如果希望重建可使用DropCreateDatabaseIfModelChanges实现每次变动后重建数据库。. 本例中我们直接使用Migration方法,更多信息请查看 Code First Migrations.
启用Code First Migrations
工具菜单,选择Library Package Manager ,Package Manager Console.
PM>
提示符下输入如下命令:enable-migrations -contexttypename SchoolContext
命令将创建 Migrations文件夹,并在文件夹下创建Configuration.cs.
Configuration
类包含Seed
方法,数据库创建或更新后将调用此方法。internalsealedclassConfiguration:DbMigrationsConfiguration<ContosoUniversity.Models.SchoolContext>{publicConfiguration(){AutomaticMigrationsEnabled=false;}protectedoverridevoidSeed(ContosoUniversity.Models.SchoolContext context){// This method will be called after migrating to the latest version.// You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g.//// context.People.AddOrUpdate(// p => p.FullName,// new Person { FullName = "Andrew Peters" },// new Person { FullName = "Brice Lambson" },// new Person { FullName = "Rowan Miller" }// );//}}
Seed
方法使得可设置自动插入到数据库中的数据
设置Seed方法
为了便于测试,我们在Seed中添加一些数据
- 替换 Configuration.cs内容如下:
namespaceContosoUniversity.Migrations{usingSystem;usingSystem.Collections.Generic;usingSystem.Data.Entity.Migrations;usingSystem.Linq;usingContosoUniversity.Models;internalsealedclassConfiguration:DbMigrationsConfiguration<ContosoUniversity.DAL.SchoolContext>{publicConfiguration(){AutomaticMigrationsEnabled=false;}protectedoverridevoidSeed(ContosoUniversity.DAL.SchoolContext context){var students =newList<Student>{newStudent{FirstMidName="Carson",LastName="Alexander",EnrollmentDate=DateTime.Parse("2010-09-01")},newStudent{FirstMidName="Meredith",LastName="Alonso",EnrollmentDate=DateTime.Parse("2012-09-01")},newStudent{FirstMidName="Arturo",LastName="Anand",EnrollmentDate=DateTime.Parse("2013-09-01")},newStudent{FirstMidName="Gytis",LastName="Barzdukas",EnrollmentDate=DateTime.Parse("2012-09-01")},newStudent{FirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2012-09-01")},newStudent{FirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2011-09-01")},newStudent{FirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2013-09-01")},newStudent{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2005-08-11")}};
students.ForEach(s => context.Students.AddOrUpdate(p => p.LastName, s));
context.SaveChanges();var courses =newList<Course>{newCourse{CourseID=1050,Title="Chemistry",Credits=3,},newCourse{CourseID=4022,Title="Microeconomics",Credits=3,},newCourse{CourseID=4041,Title="Macroeconomics",Credits=3,},newCourse{CourseID=1045,Title="Calculus",Credits=4,},newCourse{CourseID=3141,Title="Trigonometry",Credits=4,},newCourse{CourseID=2021,Title="Composition",Credits=3,},newCourse{CourseID=2042,Title="Literature",Credits=4,}};
courses.ForEach(s => context.Courses.AddOrUpdate(p => p.Title, s));
context.SaveChanges();var enrollments =newList<Enrollment>{newEnrollment{StudentID= students.Single(s => s.LastName=="Alexander").StudentID,CourseID= courses.Single(c => c.Title=="Chemistry").CourseID,Grade=Grade.A
},newEnrollment{StudentID= students.Single(s => s.LastName=="Alexander").StudentID,CourseID= courses.Single(c => c.Title=="Microeconomics").CourseID,Grade=Grade.C
},newEnrollment{StudentID= students.Single(s => s.LastName=="Alexander").StudentID,CourseID= courses.Single(c => c.Title=="Macroeconomics").CourseID,Grade=Grade.B
},newEnrollment{StudentID= students.Single(s => s.LastName=="Alonso").StudentID,CourseID= courses.Single(c => c.Title=="Calculus").CourseID,Grade=Grade.B
},newEnrollment{StudentID= students.Single(s => s.LastName=="Alonso").StudentID,CourseID= courses.Single(c => c.Title=="Trigonometry").CourseID,Grade=Grade.B
},newEnrollment{StudentID= students.Single(s => s.LastName=="Alonso").StudentID,CourseID= courses.Single(c => c.Title=="Composition").CourseID,Grade=Grade.B
},newEnrollment{StudentID= students.Single(s => s.LastName=="Anand").StudentID,CourseID= courses.Single(c => c.Title=="Chemistry").CourseID},newEnrollment{StudentID= students.Single(s => s.LastName=="Anand").StudentID,CourseID= courses.Single(c => c.Title=="Microeconomics").CourseID,Grade=Grade.B
},newEnrollment{StudentID= students.Single(s => s.LastName=="Barzdukas").StudentID,CourseID= courses.Single(c => c.Title=="Chemistry").CourseID,Grade=Grade.B
},newEnrollment{StudentID= students.Single(s => s.LastName=="Li").StudentID,CourseID= courses.Single(c => c.Title=="Composition").CourseID,Grade=Grade.B
},newEnrollment{StudentID= students.Single(s => s.LastName=="Justice").StudentID,CourseID= courses.Single(c => c.Title=="Literature").CourseID,Grade=Grade.B
}};foreach(Enrollment e in enrollments){var enrollmentInDataBase = context.Enrollments.Where(
s =>
s.Student.StudentID== e.StudentID&&
s.Course.CourseID== e.CourseID).SingleOrDefault();if(enrollmentInDataBase ==null){
context.Enrollments.Add(e);}}
context.SaveChanges();}}}由于此方法在创建或更新后调用,为了避免多次插入同一数据,调用AddOrUpdate方法,第一个参数用来检查数据是否已经存在。
context.Students.AddOrUpdate(p => p.LastName, s)
关于更多AddOrUpdate信息,请查看 Take care with EF 4.3 AddOrUpdate Method on Julie Lerman's blog.
foreach(Enrollment e in enrollments){var enrollmentInDataBase = context.Enrollments.Where(
s => s.Student.StudentID== e.Student.StudentID&&
s.Course.CourseID== e.Course.CourseID).SingleOrDefault();if(enrollmentInDataBase ==null){
context.Enrollments.Add(e);}}关于Seed中问题的调试,请查看 Seeding and Debugging Entity Framework (EF) DBs on Rick Anderson's blog.
编译.
创建并执行 First Migration
- 在 the Package Manager Console 执行命令:
add-migration InitialCreate
update-databaseadd-migration
命令将添加 [DateStamp]_InitialCreate.cs 文件到Migrations文件夹,文件中包含数据库创建初始化信息。第一个参数 (InitialCreate)
作为文件名,前面会加上时间戳.InitialCreate
文件代码如下:namespaceContosoUniversity.Migrations{usingSystem;usingSystem.Data.Entity.Migrations;publicpartialclassInitialCreate:DbMigration{publicoverridevoidUp(){CreateTable("dbo.Student",
c =>new{StudentID= c.Int(nullable:false, identity:true),LastName= c.String(),FirstMidName= c.String(),EnrollmentDate= c.DateTime(nullable:false),}).PrimaryKey(t => t.StudentID);CreateTable("dbo.Enrollment",
c =>new{EnrollmentID= c.Int(nullable:false, identity:true),CourseID= c.Int(nullable:false),StudentID= c.Int(nullable:false),Grade= c.Int(),}).PrimaryKey(t => t.EnrollmentID).ForeignKey("dbo.Course", t => t.CourseID, cascadeDelete:true).ForeignKey("dbo.Student", t => t.StudentID, cascadeDelete:true).Index(t => t.CourseID).Index(t => t.StudentID);CreateTable("dbo.Course",
c =>new{CourseID= c.Int(nullable:false),Title= c.String(),Credits= c.Int(nullable:false),}).PrimaryKey(t => t.CourseID);}publicoverridevoidDown(){DropIndex("dbo.Enrollment",new[]{"StudentID"});DropIndex("dbo.Enrollment",new[]{"CourseID"});DropForeignKey("dbo.Enrollment","StudentID","dbo.Student");DropForeignKey("dbo.Enrollment","CourseID","dbo.Course");DropTable("dbo.Course");DropTable("dbo.Enrollment");DropTable("dbo.Student");}}}The
update-database
运行文件中的Up
方法创建数据库,然后调用Seed
方法.
名为 ContosoUniversity的数据库将被创建, .mdf文件被存放在 App_Data 文件夹,如你在连接字符串指定的一致.
以下步骤是在VS中查看数据库的操作,按图所示操作即可,不再翻译。
From the View menu, click Server Explorer.
Click the Add Connection icon.
If you are prompted with the Choose Data Source dialog, click Microsoft SQL Server, and then clickContinue.
In the Add Connection dialog box, enter (localdb)\v11.0 for the Server Name. Under Select or enter a database name, select ContosoUniversity.
Click OK.
Expand SchoolContext and then expand Tables.
Right-click the Student table and click Show Table Data to see the columns that were created and the rows that were inserted into the table.
创建Student Controller and Views
- 右击Controllers文件夹,选择创建Controller,相关参数信息如下图所示:
Visual Studio 打开 Controllers\StudentController.cs file. 数据库上下文对象已经创建
privateSchoolContext db =newSchoolContext();
Index
action method 从数据库上下文获取Students
属性,返回学生列表:publicViewResultIndex(){returnView(db.Students.ToList());}
The Student\Index.cshtml 视图显示了列表中的信息:
<table><tr><th>
@Html.DisplayNameFor(model => model.LastName)
</th><th>
@Html.DisplayNameFor(model => model.FirstMidName)
</th><th>
@Html.DisplayNameFor(model => model.EnrollmentDate)
</th><th></th></tr> @foreach (var item in Model) {
<tr><td>
@Html.DisplayFor(modelItem => item.LastName)
</td><td>
@Html.DisplayFor(modelItem => item.FirstMidName)
</td><td>
@Html.DisplayFor(modelItem => item.EnrollmentDate)
</td><td>
@Html.ActionLink("Edit", "Edit", new { id=item.StudentID }) |
@Html.ActionLink("Details", "Details", new { id=item.StudentID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.StudentID })
</td></tr>
}Press CTRL+F5 运行。
点击Students 查看。
惯例
EF的这些惯例,使得以上所写代码不多:
- 实体类名得复数形式作为表名.
- 实体类的属性名作为表的列名.
ID
或 classnameID
作为主键.
惯例可以不必遵守(如本文不用复数形式作为表名),如果使用惯例或者覆盖惯例,请查看后面的 Creating a More Complex Data Model 。更多信息请查看. Code First Conventions.
总结
使用 Entity Framework 和SQL Server Express 创建了一个简单的web程序。随后将学习如何完成基本的 CRUD (create, read, update, delete) 操作.
MVC中使用EF(1):为ASP.NET MVC程序创建Entity Framework数据模型的更多相关文章
- MVC中使用EF(2):实现基本的CRUD功能
MVC中使用EF(2):实现基本的CRUD功能 By Tom Dykstra |July 30, 2013 Translated by litdwg Contoso University示例网站 ...
- ASP.NET MVC 4 (十一) Bundles和显示模式--asp.net mvc中 @Scripts.Render("~/bundles/jquery")是什么意思? 在布局文件中使用Scripts.Render()输出脚本包,Styles.Render()输出风格包:
ASP.NET MVC 4 (十一) Bundles和显示模式 ASP.NET MVC 4 引入的js打包压缩功能.打包压缩jquery目录下的文件,在布局文件中使用Scripts.Render()输 ...
- 自学MVC看这里——全网最全ASP.NET MVC 教程汇总
MVC架构已深得人心,微软也不甘落后,推出了Asp.net MVC.小编特意整理博客园乃至整个网络最具价值的MVC技术原创文章,为想要学习ASP.NET MVC技术的学习者提供一个整合学习入口.本文从 ...
- 自学MVC看这里——全网最全ASP.NET MVC 教程汇总(转)
自学MVC看这里——全网最全ASP.NET MVC 教程汇总 MVC架构已深得人心,微软也不甘落后,推出了Asp.net MVC.小编特意整理博客园乃至整个网络最具价值的MVC技术原创文章,为想要 ...
- 自学MVC看这里——全网最全ASP.NET MVC 教程汇总【转】
自学MVC看这里——全网最全ASP.NET MVC 教程汇总 http://www.cnblogs.com/powertoolsteam/archive/2015/08/13/4667892.html ...
- 学习ASP.NET MVC(七)——我的第一个ASP.NET MVC 查询页面
在本篇文章中,我将添加一个新的查询页面(SearchIndex),可以按书籍的种类或名称来进行查询.这个新页面的网址是http://localhost:36878/Book/ SearchIndex. ...
- 学习ASP.NET MVC(三)——我的第一个ASP.NET MVC 视图
今天我将对前一篇文章中的示例进行修改,前一篇文章中并没有用到视图,这次将用到视图.对于前一个示例中的HelloWorldController类进行修改,使用视图模板文件生成HTML响应给浏览器. 一. ...
- 学习ASP.NET MVC(一)——我的第一个ASP.NET MVC应用程序
学习ASP.NET MVC系列: 学习ASP.NET MVC(一)——我的第一个ASP.NET MVC应用程序 学习ASP.NET MVC(二)——我的第一个ASP.NET MVC 控制器 学习ASP ...
- 关于在ASP.NET MVC 中使用EF的Code First的方式来读取数据库时的Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
今天在做一个小网站的时候遇到很多问题唉,我还是个菜鸟,懂的也不多,今天一个表单的提交按钮用不了,都弄了几个小时唉.不过最后还是搞定了,还有浏览器有开发人员选项,不然我都不知道我还要继续排查多久哦,今天 ...
随机推荐
- jsf标签,jsp标签与jstl标签
JSF通过定制标签与JSP集成.之前展示过的所有 JSF标签,<h:inputText>.<h:outputText>.<h:form> 和<f:view&g ...
- JavaScript学习总结(二)
JavaScript学习总结(二) ---- 对象 在JavaScript中,几乎用到的每个js都离不开它的对象.下面我们深入了解一下js对象. js中对象的分类跟之前我们学过的语言中函数的分类一样, ...
- sybase从表A创建表B
sybase从表A创建表B 例如:需要创建一张表B,表的内容及结构跟表A完全一样,类似于SQL SERVER中的CREATE TABLE A AS SELECT * FROM B; 在sybase中只 ...
- 将宿主机东西拷贝到dokcer容器中去
1,获取容器名称或者id : docker ps 2,获取整个容器的id,其实键盘tag就可以补全的. docker inspect -f '{{.Id}}' 步骤A获取的名称或者id 3,在主机 ...
- DotNet程序汉化过程--SnippetCompiler准确定位
开篇前言 上一篇简单介绍了一下怎么汉化.Net程序,但那也仅仅是最基础的工作,要想汉化好一款软件基础我们得做扎实了,但是对于一些需要技巧的也不能不会啊,这一篇就介绍一下怎么准确定位字符串. 主要使用工 ...
- QTableWidget简单操作
使用Qt设计师工具,在窗体上添加Table Widget控件,这样就可以使用ui全局变量来调用该控件了. Table Widget控件的应用 (1)设置列数和行数 //设¦¨¨置?列¢D数ºy和¨ª行 ...
- memcached介绍及基本使用
一:概念 memcached是LiveJournal旗下Danga Interactive 公司的Brad Fitzpatric 为首开发的一款软件.现在已成为mixi,hatena,facebook ...
- 慕课linux学习笔记(九)常用命令(6)
关机与重启命令 Shutdown [选项] 时间 -c 取消前一个关机命令 -h 关机 -r 重启 Shutdown -r now 其他关机命令 Halt Poweroff Init 0 其他重启命令 ...
- 一个支持实时预览的在线 Markdown 编辑器 - Markdoc
最近组内需要为一些项目和系统写文档,发表在公司内的文档平台上,这个平台并不支持markdown,所以打算做一个在线markdown编辑器,支持实时预览,并且可以很容易的迁移发表到公司文档平台上,所以就 ...
- 基于lucene的案例开发:查询语句创建PackQuery
转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/44656141 http://www.llwjy.com/blogdetail/1 ...