entity framework

main
syneffort 2 years ago
parent 011a268535
commit 476a678d12
  1. 11
      AspNetFrameworkMVC/AspNetFrameworkMVC/AspNetFrameworkMVC.csproj
  2. 27
      AspNetFrameworkMVC/AspNetFrameworkMVC/Controllers/HomeController.cs
  3. 13
      AspNetFrameworkMVC/AspNetFrameworkMVC/Models/Guest.cs
  4. 17
      AspNetFrameworkMVC/AspNetFrameworkMVC/Views/Home/ShowGuests.cshtml
  5. 15
      AspNetFrameworkMVC/AspNetFrameworkMVC/Web.config
  6. 1
      AspNetFrameworkMVC/AspNetFrameworkMVC/packages.config
  7. 25
      Framework2.0Test/Framework2.0Test.sln
  8. 44
      Framework2.0Test/Framework2.0Test/Framework2.0Test.csproj
  9. 38
      Framework2.0Test/Framework2.0Test/Program.cs
  10. 36
      Framework2.0Test/Framework2.0Test/Properties/AssemblyInfo.cs

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" /> <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
@ -45,6 +46,12 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
@ -186,6 +193,7 @@
<Content Include="Views\Home\MyView.cshtml" /> <Content Include="Views\Home\MyView.cshtml" />
<Content Include="Views\Home\MyViewRazor.cshtml" /> <Content Include="Views\Home\MyViewRazor.cshtml" />
<Content Include="Views\Home\GuestRazor.cshtml" /> <Content Include="Views\Home\GuestRazor.cshtml" />
<Content Include="Views\Home\ShowGuests.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<ItemGroup> <ItemGroup>
@ -248,7 +256,10 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" /> <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
</Target> </Target>
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">

@ -118,5 +118,32 @@ namespace AspNetFrameworkMVC.Controllers
return View(guest); return View(guest);
} }
public ActionResult AddGuest()
{
string name = Request["name"];
string msg = Request["msg"];
var db = new GuestDbContext();
Guest g = new Guest()
{
Name = name,
CreatedDate = DateTime.Now,
Message = msg
};
db.Guests.Add(g);
db.SaveChanges();
return RedirectToAction("ShowGuests");
}
public ActionResult ShowGuests()
{
var db = new GuestDbContext();
List<Guest> guests = db.Guests.OrderByDescending(g => g.Id).Take(10).ToList();
return View(guests);
}
} }
} }

@ -1,10 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
namespace AspNetFrameworkMVC.Models namespace AspNetFrameworkMVC.Models
{ {
[Table("Guest")]
public class Guest public class Guest
{ {
public int Id { get; set; } public int Id { get; set; }
@ -12,4 +15,14 @@ namespace AspNetFrameworkMVC.Models
public DateTime CreatedDate { get; set; } public DateTime CreatedDate { get; set; }
public string Message { get; set; } public string Message { get; set; }
} }
public class GuestDbContext : DbContext
{
public GuestDbContext() : base()
{
}
public DbSet<Guest> Guests { get; set; }
}
} }

@ -0,0 +1,17 @@
@using AspNetFrameworkMVC.Models
@{
ViewBag.Title = "ShowGuests";
List<Guest> guests = (List<Guest>)Model;
}
<h2>ShowGuests</h2>
<p>
@for (int i = 0; i < guests.Count; i++)
{
Guest guest = guests[i];
string text = $"Id: {guest.Id}, Name: {guest.Name}, CreatedDate: {guest.CreatedDate}, Message: {guest.Message}";
<div>@text</div>
}
</p>

@ -4,6 +4,10 @@
https://go.microsoft.com/fwlink/?LinkId=301880 https://go.microsoft.com/fwlink/?LinkId=301880
--> -->
<configuration> <configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings> <appSettings>
<add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" /> <add key="webpages:Enabled" value="false" />
@ -34,7 +38,7 @@
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /> <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
@ -57,7 +61,12 @@
</compilers> </compilers>
</system.codedom> </system.codedom>
<connectionStrings> <connectionStrings>
<add name="Default" connectionString="server=peacecloud.synology.me,21433;database=study;uid=study;pwd=Study1234" /> <add name="GuestDbContext" connectionString="server=peacecloud.synology.me,21433;database=study;uid=study;pwd=Study1234" providerName="System.Data.SqlClient" />
<add name="Local" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Works\Development\TestDevs\dotNetWebStudy\AspNetFrameworkMVC\AspNetFrameworkMVC\App_Data\SampleDB.mdf;Integrated Security=True" /> <add name="GuestDbContext_Local" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Works\Development\TestDevs\dotNetWebStudy\AspNetFrameworkMVC\AspNetFrameworkMVC\App_Data\SampleDB.mdf;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings> </connectionStrings>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration> </configuration>

@ -2,6 +2,7 @@
<packages> <packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net45" /> <package id="Antlr" version="3.5.0.2" targetFramework="net45" />
<package id="bootstrap" version="5.2.3" targetFramework="net45" /> <package id="bootstrap" version="5.2.3" targetFramework="net45" />
<package id="EntityFramework" version="6.4.4" targetFramework="net45" />
<package id="jQuery" version="3.4.1" targetFramework="net45" /> <package id="jQuery" version="3.4.1" targetFramework="net45" />
<package id="jQuery.Validation" version="1.17.0" targetFramework="net45" /> <package id="jQuery.Validation" version="1.17.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.2.9" targetFramework="net45" /> <package id="Microsoft.AspNet.Mvc" version="5.2.9" targetFramework="net45" />

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework2.0Test", "Framework2.0Test\Framework2.0Test.csproj", "{26660D93-8F5A-4B06-9FEC-0F3A4BA02462}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{26660D93-8F5A-4B06-9FEC-0F3A4BA02462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26660D93-8F5A-4B06-9FEC-0F3A4BA02462}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26660D93-8F5A-4B06-9FEC-0F3A4BA02462}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26660D93-8F5A-4B06-9FEC-0F3A4BA02462}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC1B4EAF-697A-4E8D-9D61-FBC9FB849963}
EndGlobalSection
EndGlobal

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{26660D93-8F5A-4B06-9FEC-0F3A4BA02462}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Framework2._0Test</RootNamespace>
<AssemblyName>Framework2.0Test</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace Framework2._0Test
{
internal class Program
{
static void Main(string[] args)
{
DateTime dd = new DateTime();
Console.WriteLine(dd);
Process[] processList;
processList = Process.GetProcessesByName("cmd");
KillProcesses(processList);
processList = Process.GetProcessesByName("powershell");
KillProcesses(processList);
Console.ReadKey();
}
private static void KillProcesses(Process[] processes)
{
if (processes == null || processes.Length < 1)
return;
foreach (Process process in processes)
{
process.Kill();
}
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("Framework2.0Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Framework2.0Test")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("26660d93-8f5a-4b06-9fec-0f3a4ba02462")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading…
Cancel
Save