diff --git a/Tasks/Lab9/EntityFramework/EF6_Code_First/App.config b/Tasks/Lab9/EntityFramework/EF6_Code_First/App.config new file mode 100644 index 0000000..8487c30 --- /dev/null +++ b/Tasks/Lab9/EntityFramework/EF6_Code_First/App.config @@ -0,0 +1,18 @@ + + + + +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/Tasks/Lab9/EntityFramework/EF6_Code_First/EF6_Code_First.csproj b/Tasks/Lab9/EntityFramework/EF6_Code_First/EF6_Code_First.csproj new file mode 100644 index 0000000..b373438 --- /dev/null +++ b/Tasks/Lab9/EntityFramework/EF6_Code_First/EF6_Code_First.csproj @@ -0,0 +1,76 @@ + + + + + + Debug + AnyCPU + {9E452FB4-1B73-4A13-B338-FA33CD0866BC} + Exe + EF6_Code_First + EF6_Code_First + v4.8.1 + 512 + true + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + 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}. + + + + + + \ No newline at end of file diff --git a/Tasks/Lab9/EntityFramework/EF6_Code_First/FlughafenModell.cs b/Tasks/Lab9/EntityFramework/EF6_Code_First/FlughafenModell.cs new file mode 100644 index 0000000..35b6b01 --- /dev/null +++ b/Tasks/Lab9/EntityFramework/EF6_Code_First/FlughafenModell.cs @@ -0,0 +1,24 @@ +using EF6_Code_First.Migrations; +using System; +using System.Data.Entity; +using System.Linq; + +namespace EF6_Code_First +{ + public class FlughafenModell : DbContext + { + // Your context has been configured to use a 'FlughafenModell' connection string from your application's + // configuration file (App.config or Web.config). By default, this connection string targets the + // 'EF6_Code_First.FlughafenModell' database on your LocalDb instance. + // + // If you wish to target a different database and/or database provider, modify the 'FlughafenModell' + // connection string in the application configuration file. + public FlughafenModell() + : base("data source=(local);initial catalog=FlughafenDB;integrated security=True;MultipleActiveResultSets=True;") + { + Database.SetInitializer(new MigrateDatabaseToLatestVersion()); + } + + public virtual DbSet Lands { get; set; } + } +} \ No newline at end of file diff --git a/Tasks/Lab9/EntityFramework/EF6_Code_First/Migrations/Configuration.cs b/Tasks/Lab9/EntityFramework/EF6_Code_First/Migrations/Configuration.cs new file mode 100644 index 0000000..17d8e3c --- /dev/null +++ b/Tasks/Lab9/EntityFramework/EF6_Code_First/Migrations/Configuration.cs @@ -0,0 +1,24 @@ +namespace EF6_Code_First.Migrations +{ + using System; + using System.Data.Entity; + using System.Data.Entity.Migrations; + using System.Linq; + + internal sealed class Configuration : DbMigrationsConfiguration + { + public Configuration() + { + AutomaticMigrationsEnabled = true; + AutomaticMigrationDataLossAllowed = true; + } + + protected override void Seed(EF6_Code_First.FlughafenModell context) + { + // This method will be called after migrating to the latest version. + + // You can use the DbSet.AddOrUpdate() helper extension method + // to avoid creating duplicate seed data. + } + } +} diff --git a/Tasks/Lab9/EntityFramework/EF6_Code_First/Program.cs b/Tasks/Lab9/EntityFramework/EF6_Code_First/Program.cs new file mode 100644 index 0000000..30003df --- /dev/null +++ b/Tasks/Lab9/EntityFramework/EF6_Code_First/Program.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EF6_Code_First +{ + internal class Program + { + static void Main(string[] args) + { + using (var db = new FlughafenModell()) + { + // Create and save a new country + Console.Write("Enter a name for a new Country: "); + var name = Console.ReadLine(); + var land = new Land { Name = name }; + //db.Lands.Add(land); + db.SaveChanges(); + // Display all Countries from the database + var query = from b in db.Lands + orderby b.Name + select b; + Console.WriteLine("All countries in the database:"); + foreach (var item in query) + { + Console.WriteLine(item.Name); + } + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); + } + } + } + + public class Land + { + public int LandId { get; set; } + + [StringLength(50)] + [Index("IX_Name", IsClustered = false, IsUnique = true)] + public string Name { get; set; } + + public ICollection Continent { get; set; } + } + + public class Continent + { + public int ContinentId { get; set; } + public string Name { get; set; } + } +} diff --git a/Tasks/Lab9/EntityFramework/EF6_Code_First/Properties/AssemblyInfo.cs b/Tasks/Lab9/EntityFramework/EF6_Code_First/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6c37daf --- /dev/null +++ b/Tasks/Lab9/EntityFramework/EF6_Code_First/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EF6_Code_First")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EF6_Code_First")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9e452fb4-1b73-4a13-b338-fa33cd0866bc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tasks/Lab9/EntityFramework/EF6_Code_First/packages.config b/Tasks/Lab9/EntityFramework/EF6_Code_First/packages.config new file mode 100644 index 0000000..4539f0c --- /dev/null +++ b/Tasks/Lab9/EntityFramework/EF6_Code_First/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Tasks/Lab9/EntityFramework/EntityFramework.sln b/Tasks/Lab9/EntityFramework/EntityFramework.sln index 88d8662..9cbdd68 100644 --- a/Tasks/Lab9/EntityFramework/EntityFramework.sln +++ b/Tasks/Lab9/EntityFramework/EntityFramework.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF6", "EF6\EF6.csproj", "{77C9116F-B7B7-4270-AD32-49C310D6546C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF6_Code_First", "EF6_Code_First\EF6_Code_First.csproj", "{9E452FB4-1B73-4A13-B338-FA33CD0866BC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {77C9116F-B7B7-4270-AD32-49C310D6546C}.Debug|Any CPU.Build.0 = Debug|Any CPU {77C9116F-B7B7-4270-AD32-49C310D6546C}.Release|Any CPU.ActiveCfg = Release|Any CPU {77C9116F-B7B7-4270-AD32-49C310D6546C}.Release|Any CPU.Build.0 = Release|Any CPU + {9E452FB4-1B73-4A13-B338-FA33CD0866BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E452FB4-1B73-4A13-B338-FA33CD0866BC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E452FB4-1B73-4A13-B338-FA33CD0866BC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E452FB4-1B73-4A13-B338-FA33CD0866BC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE