Commit 7faed73a authored by Kirill's avatar Kirill

Удаление примера

parent bd52fed8
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="footballDb" connectionString="data source=my.sqlite;foreign keys=true" providerName="System.Data.SQLite" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
</configuration>
\ No newline at end of file
namespace SQLite.CodeFirst.Console.Entity
{
public class Coach : Person
{
public virtual Team Team { get; set; }
}
}
using System;
namespace SQLite.CodeFirst.Console.Entity
{
public class CustomHistory : IHistory
{
public int Id { get; set; }
public string Hash { get; set; }
public string Context { get; set; }
public DateTime CreateDate { get; set; }
}
}
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace SQLite.CodeFirst.Console.Entity
{
/// <summary>
/// See https://github.com/msallin/SQLiteCodeFirst/issues/69 and https://github.com/msallin/SQLiteCodeFirst/issues/63
/// </summary>
public class Foo
{
private ICollection<FooSelf> _fooSelves;
private ICollection<FooStep> _fooSteps;
public int FooId { get; set; }
public string Name { get; set; }
public int? FooSelf1Id { get; set; }
public int? FooSelf2Id { get; set; }
public int? FooSelf3Id { get; set; }
[ForeignKey("FooSelf1Id")]
public virtual Foo ParentMyEntity1 { get; set; }
[ForeignKey("FooSelf2Id")]
public virtual Foo ParentMyEntity2 { get; set; }
[ForeignKey("FooSelf3Id")]
public virtual Foo ParentMyEntity3 { get; set; }
public virtual ICollection<FooStep> FooSteps
{
get { return _fooSteps ?? (_fooSteps = new HashSet<FooStep>()); }
set { _fooSteps = value; }
}
public virtual ICollection<FooSelf> FooSelves
{
get { return _fooSelves ?? (_fooSelves = new HashSet<FooSelf>()); }
set { _fooSelves = value; }
}
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SQLite.CodeFirst.Console.Entity
{
/// <summary>
/// See https://github.com/msallin/SQLiteCodeFirst/issues/109
/// </summary>
public class FooCompositeKey
{
[Key, Column(Order = 1)]
public int Id { get; set; }
[Key, Column(Order = 2), StringLength(20)]
public string Version { get; set; }
[StringLength(255)]
public string Name { get; set; }
public virtual ICollection<FooRelationshipA> FooeyACollection { get; set; }
public virtual ICollection<FooRelationshipB> FooeyBCollection { get; set; }
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace SQLite.CodeFirst.Console.Entity
{
/// <summary>
/// See https://github.com/msallin/SQLiteCodeFirst/issues/109
/// </summary>
public class FooRelationshipA
{
public int Id { get; set; }
[StringLength(255)]
public string Name { get; set; }
public virtual ICollection<FooCompositeKey> Fooey { get; set; }
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace SQLite.CodeFirst.Console.Entity
{
/// <summary>
/// See https://github.com/msallin/SQLiteCodeFirst/issues/109
/// </summary>
public class FooRelationshipB
{
public int Id { get; set; }
[StringLength(255)]
public string Name { get; set; }
public virtual ICollection<FooCompositeKey> Fooey { get; set; }
}
}
\ No newline at end of file
namespace SQLite.CodeFirst.Console.Entity
{
/// <summary>
/// See https://github.com/msallin/SQLiteCodeFirst/issues/69 and https://github.com/msallin/SQLiteCodeFirst/issues/63
/// </summary>
public class FooSelf
{
public int FooSelfId { get; set; }
public int FooId { get; set; }
public int Number { get; set; }
public virtual Foo Foo { get; set; }
}
}
\ No newline at end of file
namespace SQLite.CodeFirst.Console.Entity
{
/// <summary>
/// See https://github.com/msallin/SQLiteCodeFirst/issues/69 and https://github.com/msallin/SQLiteCodeFirst/issues/63
/// </summary>
public class FooStep
{
public int FooStepId { get; set; }
public int FooId { get; set; }
public int Number { get; set; }
public virtual Foo Foo { get; set; }
}
}
\ No newline at end of file
namespace SQLite.CodeFirst.Console.Entity
{
interface IEntity
{
int Id { get; set; }
}
}
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SQLite.CodeFirst.Console.Entity
{
public abstract class Person : IEntity
{
public int Id { get; set; }
[MaxLength(50)]
[Collate(CollationFunction.NoCase)]
public string FirstName { get; set; }
[MaxLength(50)]
public string LastName { get; set; }
[MaxLength(100)]
public string Street { get; set; }
[Required]
public string City { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[SqlDefaultValue(DefaultValue = "DATETIME('now')")]
public DateTime CreatedUtc { get; set; }
}
}
using System.ComponentModel.DataAnnotations.Schema;
namespace SQLite.CodeFirst.Console.Entity
{
[Table("TeamPlayer")]
public class Player : Person
{
[Index] // Automatically named 'IX_TeamPlayer_Number'
[Index("IX_TeamPlayer_NumberPerTeam", Order = 1, IsUnique = true)]
public int Number { get; set; }
// The index attribute must be placed on the FK not on the navigation property (team).
[Index("IX_TeamPlayer_NumberPerTeam", Order = 2, IsUnique = true)]
public int TeamId { get; set; }
// Its not possible to set an index on this property. Use the FK property (teamId).
public virtual Team Team { get; set; }
public virtual Player Mentor { get; set; }
}
}
\ No newline at end of file
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SQLite.CodeFirst.Console.Entity
{
public class Stadion
{
[Key]
[Column(Order = 1)]
[Index("IX_Stadion_Main", Order = 2, IsUnique = true)] // Test for combined, named index
public string Name { get; set; }
[Key]
[Column(Order = 2)]
[Index("IX_Stadion_Main", Order = 1, IsUnique = true)] // Test for combined, named index
public string Street { get; set; }
[Key]
[Column(Order = 3)]
public string City { get; set; }
[Column(Order = 4)]
[Index("ReservedKeyWordTest", IsUnique = true)]
public int Order { get; set; }
}
}
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SQLite.CodeFirst.Console.Entity
{
public class Team : IEntity
{
[Autoincrement]
public int Id { get; set; }
[Index("IX_Team_TeamsName")] // Test for named index.
[Required]
public string Name { get; set; }
public virtual Coach Coach { get; set; }
public virtual ICollection<Player> Players { get; set; }
public virtual Stadion Stadion { get; set; }
}
}
\ No newline at end of file
using System.Data.Common;
using System.Data.Entity;
namespace SQLite.CodeFirst.Console
{
public class FootballDbContext : DbContext
{
public FootballDbContext(string nameOrConnectionString)
: base(nameOrConnectionString)
{
Configure();
}
public FootballDbContext(DbConnection connection, bool contextOwnsConnection)
: base(connection, contextOwnsConnection)
{
Configure();
}
private void Configure()
{
Configuration.ProxyCreationEnabled = true;
Configuration.LazyLoadingEnabled = true;
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
ModelConfiguration.Configure(modelBuilder);
var initializer = new FootballDbInitializer(modelBuilder);
Database.SetInitializer(initializer);
}
}
}
\ No newline at end of file
using System.Data.Entity;
using SQLite.CodeFirst.Console.Entity;
namespace SQLite.CodeFirst.Console
{
public class FootballDbInitializer : SqliteDropCreateDatabaseWhenModelChanges<FootballDbContext>
{
public FootballDbInitializer(DbModelBuilder modelBuilder)
: base(modelBuilder, typeof(CustomHistory))
{ }
protected override void Seed(FootballDbContext context)
{
// Here you can seed your core data if you have any.
}
}
}
\ No newline at end of file
using System.Data.Entity;
using SQLite.CodeFirst.Console.Entity;
namespace SQLite.CodeFirst.Console
{
public class ModelConfiguration
{
public static void Configure(DbModelBuilder modelBuilder)
{
ConfigureTeamEntity(modelBuilder);
ConfigureStadionEntity(modelBuilder);
ConfigureCoachEntity(modelBuilder);
ConfigurePlayerEntity(modelBuilder);
ConfigureSelfReferencingEntities(modelBuilder);
ConfigureCompositeKeyEntities(modelBuilder);
}
private static void ConfigureTeamEntity(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Team>().ToTable("Base.MyTable")
.HasRequired(t => t.Coach)
.WithMany()
.WillCascadeOnDelete(false);
modelBuilder.Entity<Team>()
.HasRequired(t => t.Stadion)
.WithRequiredPrincipal()
.WillCascadeOnDelete(true);
}
private static void ConfigureStadionEntity(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Stadion>();
}
private static void ConfigureCoachEntity(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Coach>()
.HasRequired(p => p.Team)
.WithRequiredPrincipal(t => t.Coach)
.WillCascadeOnDelete(false);
}
private static void ConfigurePlayerEntity(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Player>()
.HasRequired(p => p.Team)
.WithMany(team => team.Players)
.WillCascadeOnDelete(true);
}
private static void ConfigureSelfReferencingEntities(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Foo>();
modelBuilder.Entity<FooSelf>();
modelBuilder.Entity<FooStep>();
}
private static void ConfigureCompositeKeyEntities(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<FooCompositeKey>();
modelBuilder.Entity<FooRelationshipA>();
modelBuilder.Entity<FooRelationshipB>();
}
}
}
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.SQLite;
using System.Linq;
using SQLite.CodeFirst.Console.Entity;
namespace SQLite.CodeFirst.Console
{
public static class Program
{
private static void Main()
{
StartDemoUseInMemory();
StartDemoUseFile();
PressEnterToExit();
}
private static void StartDemoUseInMemory()
{
System.Console.WriteLine("Starting Demo Application (In Memory)");
System.Console.WriteLine(string.Empty);
using (var sqLiteConnection = new SQLiteConnection("data source=:memory:"))
{
// This is required if a in memory db is used.
sqLiteConnection.Open();
using (var context = new FootballDbContext(sqLiteConnection, false))
{
CreateAndSeedDatabase(context);
DisplaySeededData(context);
}
}
}
private static void StartDemoUseFile()
{
System.Console.WriteLine("Starting Demo Application (File)");
System.Console.WriteLine(string.Empty);
using (var context = new FootballDbContext("footballDb"))
{
CreateAndSeedDatabase(context);
DisplaySeededData(context);
}
}
private static void CreateAndSeedDatabase(DbContext context)
{
System.Console.WriteLine("Create and seed the database.");
if (context.Set<Team>().Count() != 0)
{
return;
}
context.Set<Team>().Add(new Team
{
Name = "YB",
Coach = new Coach
{
City = "Zürich",
FirstName = "Masssaman",
LastName = "Nachn",
Street = "Testingstreet 844"
},
Players = new List<Player>
{
new Player
{
City = "Bern",
FirstName = "Marco",
LastName = "Bürki",
Street = "Wunderstrasse 43",
Number = 12
},
new Player
{
City = "Berlin",
FirstName = "Alain",
LastName = "Rochat",
Street = "Wonderstreet 13",
Number = 14
}
},
Stadion = new Stadion
{
Name = "Stade de Suisse",
City = "Bern",
Street = "Papiermühlestrasse 71"
}
});
context.SaveChanges();
System.Console.WriteLine("Completed.");
System.Console.WriteLine();
}
private static void DisplaySeededData(DbContext context)
{
System.Console.WriteLine("Display seeded data.");
foreach (Team team in context.Set<Team>())
{
System.Console.WriteLine("\t Team:");
System.Console.WriteLine("\t Id: {0}", team.Id);
System.Console.WriteLine("\t Name: {0}", team.Name);
System.Console.WriteLine();
System.Console.WriteLine("\t\t Stadion:");
System.Console.WriteLine("\t\t Name: {0}", team.Stadion.Name);
System.Console.WriteLine("\t\t Street: {0}", team.Stadion.Street);
System.Console.WriteLine("\t\t City: {0}", team.Stadion.City);
System.Console.WriteLine();
System.Console.WriteLine("\t\t Coach:");
System.Console.WriteLine("\t\t Id: {0}", team.Coach.Id);
System.Console.WriteLine("\t\t FirstName: {0}", team.Coach.FirstName);
System.Console.WriteLine("\t\t LastName: {0}", team.Coach.LastName);
System.Console.WriteLine("\t\t Street: {0}", team.Coach.Street);
System.Console.WriteLine("\t\t City: {0}", team.Coach.City);
System.Console.WriteLine();
foreach (Player player in team.Players)
{
System.Console.WriteLine("\t\t Player:");
System.Console.WriteLine("\t\t Id: {0}", player.Id);
System.Console.WriteLine("\t\t Number: {0}", player.Number);
System.Console.WriteLine("\t\t FirstName: {0}", player.FirstName);
System.Console.WriteLine("\t\t LastName: {0}", player.LastName);
System.Console.WriteLine("\t\t Street: {0}", player.Street);
System.Console.WriteLine("\t\t City: {0}", player.City);
System.Console.WriteLine("\t\t Created: {0}", player.CreatedUtc);
System.Console.WriteLine();
}
}
}
private static void PressEnterToExit()
{
System.Console.WriteLine();
System.Console.WriteLine("Press 'Enter' to exit.");
System.Console.ReadLine();
}
}
}
\ No newline at end of file
using System.Reflection;
[assembly: AssemblyTitle("SQLite.CodeFirst")]
[assembly: AssemblyDescription("A console application which demonstrates how to use SQLite.CodeFirst.")]
// Will be replaced by the build server
// But do not put them in a shared file, because this will break the version patching.
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{DEDABD86-6EA0-4673-A858-A4F71958F51D}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SQLite.CodeFirst.Console</RootNamespace>
<AssemblyName>SQLite.CodeFirst.Console</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug-40|AnyCPU' OR '$(Configuration)|$(Platform)' == 'Debug-45|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-40|AnyCPU' OR '$(Configuration)|$(Platform)' == 'Release-45|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\Shared\SQLite.CodeFirst.StrongNameKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\AssemblySharedInfo.cs">
<Link>Properties\AssemblySharedInfo.cs</Link>
</Compile>
<Compile Include="Entity\Coach.cs" />
<Compile Include="Entity\CustomHistory.cs" />
<Compile Include="Entity\FooCompositeKey.cs" />
<Compile Include="Entity\FooRelationshipA.cs" />
<Compile Include="Entity\FooRelationshipB.cs" />
<Compile Include="Entity\IEntity.cs" />
<Compile Include="Entity\Person.cs" />
<Compile Include="Entity\Player.cs" />
<Compile Include="Entity\Stadion.cs" />
<Compile Include="Entity\Team.cs" />
<Compile Include="Entity\Foo.cs" />
<Compile Include="Entity\FooSelf.cs" />
<Compile Include="Entity\FooStep.cs" />
<Compile Include="FootballDbContext.cs" />
<Compile Include="FootballDbInitializer.cs" />
<Compile Include="ModelConfiguration.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="SQLite.CodeFirst, Version=1.5.1.25, Culture=neutral, PublicKeyToken=eb96ba0a78d831a7">
<HintPath>..\packages\SQLite.CodeFirst.1.5.1.25\lib\net45\SQLite.CodeFirst.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.106.0\build\net451\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.106.0\build\net451\System.Data.SQLite.Core.targets'))" />
</Target>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.106.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.106.0\build\net451\System.Data.SQLite.Core.targets')" />
<!-- 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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net452" userInstalled="true" />
<package id="SQLite.CodeFirst" version="1.5.1.25" targetFramework="net452" />
<package id="System.Data.SQLite" version="1.0.106.0" targetFramework="net452" userInstalled="true" />
<package id="System.Data.SQLite.Core" version="1.0.106.0" targetFramework="net452" userInstalled="true" />
<package id="System.Data.SQLite.EF6" version="1.0.106.0" targetFramework="net452" userInstalled="true" />
<package id="System.Data.SQLite.Linq" version="1.0.106.0" targetFramework="net452" userInstalled="true" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment