-
Notifications
You must be signed in to change notification settings - Fork 3
/
description.html
215 lines (195 loc) · 13.6 KB
/
description.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><link rel="stylesheet" type="text/css" href="https://i-msdn.sec.s-msft.com/Combined.css?resources=0:Header,0:HeaderFooterSprite,0:Header.NonMtps;/Areas/Centers/Themes/StandardDevCenter/Content:0&amp;v=3A44AD9B1EA0657C0755F5E999B5CF4B" xmlns="http://www.w3.org/1999/xhtml" />
<link type="text/css" rel="stylesheet" xmlns="http://www.w3.org/1999/xhtml" />
<link rel="stylesheet" type="text/css" href="https://i-msdn.sec.s-msft.com/Combined.css?resources=0:Footer,0:HeaderFooterSprite,0:Footer.NonMtps,1:NewFooterSock,1:LinkList;/Areas/Centers/Themes/StandardDevCenter/Content:0,/Areas/Epx/Themes/Base/Content:1&amp;v=92B25B29A9FDE21FBE9E6B20A4C0376E" xmlns="http://www.w3.org/1999/xhtml" />
<link type="text/css" rel="stylesheet" xmlns="http://www.w3.org/1999/xhtml" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ASP.NET MVC Application Using Entity Framework Code First</title>
<link href="description/Galleries.css" type="text/css" rel="Stylesheet" /><link href="description/Layout.css" type="text/css" rel="Stylesheet" /><link href="description/Brand.css" type="text/css" rel="Stylesheet" />
<link href="https://i1.code.msdn.s-msft.com/content/common/iframedescription.css" rel="Stylesheet" type="text/css" />
<script src="https://i1.code.msdn.s-msft.com/content/common/offline.js" type="text/javascript"></script>
<style type="text/css">
#projectInfo {
overflow: auto;
}
#longDesc {
clear:both;
margin: 25px 0 10px 0;
}
#SampleIndexList{
margin-left: 15px;
}
</style>
</head>
<body>
<div id="offlineDescription">
<h1>ASP.NET MVC Application Using Entity Framework Code First</h1>
<br/>
<div id="projectInfo">
<div class="section">
<div class="itemBarLong tagsContainer">
<label for="Technologies">Technologies</label>
<div id="Technologies">
ADO.NET Entity Framework, ASP.NET, ASP.NET MVC, Entity Framework
</div>
</div>
<div class="itemBarLong tagsContainer">
<label for="Topics">Topics</label>
<div id="Topics">
Asynchronous Programming, Entity Framework, Concurrency, Code First, Inheritance, Lazy Loading, ASP.NET Code Sample Downloads, Data Annotation, Code First Migrations, Eager Loading, Connection Resiliency
</div>
</div>
<div class="itemBarLong">
<label for="Platforms">Platforms</label>
<div id="Platforms">
Web
</div>
</div>
<div class="itemBarLong">
<label for="Requirements">Requirements</label>
<div id="Requirements">
</div>
</div>
<div class="itemBar">
<label for="LastUpdated">Primary language</label>
<div id="LastUpdated">en-US</div>
</div>
<div class="itemBar">
<label for="LastUpdated">Updated</label>
<div id="LastUpdated">2/11/2017</div>
</div>
<div class="itemBarLong">
<label for="License">License</label>
<div id="License">
<a href="license.rtf">Apache License, Version 2.0</a></div>
</div>
<div class="itemBar">
<div class="viewonlinecont">
<a data-link="online" href="https://code.msdn.microsoft.com/ASPNET-MVC-Application-b01a9fe8">View this sample online</a>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function initializePage() {
var otherTabClass = 'otherTab';
var hiddenPreClass = 'hidden';
var htmlDecode = function(encodedData) {
var decodedData = "";
if (encodedData) {
var div = document.createElement('div');
div.innerHTML = encodedData;
decodedData = div.firstChild.nodeValue.replace( /\\r\\n/ig , '\r\n');
}
return decodedData;
};
Galleries.iterateElem(Galleries.findElem(null, 'div', 'scriptcode'), function (index, scriptBlock) {
var titleElem = Galleries.findElem(scriptBlock, 'div', 'title')[0];
var labelElems = Galleries.findElem(titleElem, 'span');
if (labelElems.length == 0) {
labelElems = titleElem;
}
var languageSpans = Galleries.findElem(scriptBlock, 'span', 'hidden');
var pres = Galleries.findElem(scriptBlock, 'pre');
if (languageSpans.length > 0 && pres.length > 1) {
Galleries.iterateElem(labelElems, function(index, elem) {
var codePre = pres[index];
var labelSpan = elem;
var languageSpan = languageSpans[index];
elem.code = codePre.innerHTML.replace( /(\r(\n)?)|((\r)?\n)/ig , '\\r\\n');
codePre.className = codePre.className.replace(hiddenPreClass, '');
languageSpan.parentNode.removeChild(languageSpan);
});
pres = Galleries.findElem(scriptBlock, 'pre');
Galleries.iterateElem(labelElems, function(index, elem) {
var codePre = pres[index];
var labelSpan = elem;
if (index == 0) {
scriptBlock.activeTab = 0;
}
else {
labelSpan.className += otherTabClass;
codePre.className += hiddenPreClass;
}
Galleries.attachEventHandler(labelSpan, 'click', function(e) {
var activeTab = scriptBlock.activeTab;
labelElems[activeTab].className += otherTabClass;
pres[activeTab].className += hiddenPreClass;
codePre.className = codePre.className.replace(hiddenPreClass, '');
labelSpan.className = labelSpan.className.replace(otherTabClass, '');
scriptBlock.activeTab = index;
});
});
var preview = Galleries.findElem(scriptBlock, 'div', 'preview');
if (preview.length == 0) {
preview.push(pres[pres.length - 1]);
}
Galleries.iterateElem(preview, function(index, elem) {
elem.parentNode.removeChild(elem);
});
if (window.clipboardData && clipboardData.setData) {
var copyLink = document.createElement('a');
copyLink.href = 'javascript:void(0);';
copyLink.className = 'copyCode';
copyLink.innerHTML = 'Copy code';
Galleries.attachEventHandler(copyLink, 'click', function (e) {
clipboardData.setData("Text", htmlDecode(labelElems[scriptBlock.activeTab].code));
return false;
});
scriptBlock.insertBefore(copyLink, scriptBlock.childNodes[0]);
}
}
});
}
Galleries.onWindowLoad(function(){
initializePage();
});
</script>
<div id="longDesc">
<p><strong>Note:</strong> A newer version is available. See the <a href="https://code.msdn.microsoft.com/ASPNET-MVC-Application-b01a9fe8/https://github.com/aspnet/Docs/tree/master/aspnetcore/data/ef-mvc/intro/samples/cu-final">VS 2015, ASP.NET Core, and EF Core sample app</a>.</p>
<h1>Introduction</h1>
<p>A Visual Studio 2013 project which shows how to use the Entity Framework 6 in an ASP.NET MVC 5 web application project, using the Code First development approach.</p>
<p>The previous version that uses EF 5 and MVC 4 in a Visual Studio 2012 project is
<a href="http://archive.msdn.microsoft.com/aspnetmvcsamples/Release/ProjectReleases.aspx?ReleaseId=6024">
available to download</a>.</p>
<p>The code illustrates the following topics:</p>
<ul>
<li>Creating a data model using data annotations attributes, and fluent API for database mapping.
</li><li>Performing basic CRUD operations. </li><li>Filtering, ordering, and grouping data. </li><li>Working with related data. </li><li>Implementing connection resiliency </li><li>Using command interception </li><li>Writing async code </li><li>Handling concurrency. </li><li>Implementing table-per-hierarchy inheritance. </li><li>Performing raw SQL queries. </li><li>Performing no-tracking queries. </li><li>Working with proxy classes. </li><li>Disabling automatic detection of changes. </li><li>Disabling validation when saving changes. </li></ul>
<p>A tutorial series describes how to build the sample application from scratch. There is an
<a href="http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application">
EF 6 MVC 5 VS 2013 tutorial series</a> and an <a href="http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application">
EF 5 MVC 4 VS 2012 tutorial series</a>.</p>
<h1>Getting Started</h1>
<p>To build and run this sample as-is, you must have Visual Studio 2013 or Visual Studio 2013 Express for Web installed. If you have Visual Studio 2015, change the connection string in the Web.config file so that the SQL Server instance name is MSSQLLocalDB
instead of v11.0.</p>
<p>In most cases you can run the application by following these steps:</p>
<ol>
<li>Download and extract the .zip file. </li><li>Open the solution file in Visual Studio. </li><li>Build the solution, which automatically installs the missing NuGet packages. </li><li>Open the Package Manager Console, and run the update-database command to create the database.
</li><li>Run the application. </li></ol>
<p>If you have any problems with those instructions, follow these longer instructions.</p>
<ol>
<li>Download the .zip file. </li><li>In File Explorer, right-click the .zip file and click Properties, then in the Properties window click Unblock.
</li><li>Unzip the file. </li><li>Double-click the .sln file to launch Visual Studio. </li><li>From the Tools menu, click Library Package Manager, then Package Manager Console.
</li><li>In the Package Manager Console (PMC), click Restore. </li><li>Exit Visual Studio. </li><li>Restart Visual Studio, opening the solution file you closed in the previous step.
</li><li>In the Package Manager Console (PMC), enter the Update-Database command. (If you get the following error:<br>
"<em>The term 'Update-Database' is not recognized as the name of a cmdlet, function, script file, or operable program</em>", exit and restart Visual Studio.)
</li><li>Each migration will run, then the seed method will run. You can now run the application.
</li></ol>
<h1>Running the Sample</h1>
<p>To run the sample, hit F5 or choose the Debug | Start Debugging menu command. You will see the home page which includes a menu bar. (In a narrow browser window you'll have to click the symbol at the top right of the page in order to see the menu.)</p>
<p>From this page you can select any of the tabs to perform various actions such as display a list of students, add new students, display a list of instructors, and so forth.</p>
<p><img src="description/StudentPagingSearch.png" id="109835" alt="" width="606" height="623"></p>
<p> </p>
<p><img src="description/InstructorEditWithCourses.png" id="109836" alt="" width="604" height="750"></p>
<h1>Source Code Overview</h1>
<p>The <em>ContosoUniversity</em> folder includes the following folders and files</p>
<ul>
<li><em>App_Data</em> folder - Holds the SQL Server Compact database file. </li><li><em>Content</em> - Holds CSS files. </li><li>Controllers - Holds controller classes. </li><li><em>DAL</em> folder - The data access layer. Holds the context, initializer, repository, and unit of work classes.
</li><li><em>Logging</em> folder - Holds code that does logging. </li><li><em>Migrations</em> folder - Holds EF Code First migrations code, including the Seed method.
</li><li><em>Models</em> folder - Holds model classes. </li><li><em>Properties</em> or <em>MyProject</em> folder - Project properties. </li><li><em>Scripts</em> folder - Script files. </li><li><em>ViewModels</em> folder - Holds view model classes. </li><li><em>Views</em> folder - Holds view classes. </li><li>Visual Studio project file (.csproj or .vbproj). </li><li><em>packages.config</em> - Specifies NuGet packages included in the project. </li><li><em>Global.asax</em> file - Includes database initializer code. </li><li>Web.config file - Includes the connection string to the database. </li></ul>
</div>
</div>
</body>
</html>