EF 5
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using MileageTraker.Web.Utility;
|
||||
|
||||
namespace MileageTraker.Web.Models
|
||||
|
||||
+49
-48
@@ -1,28 +1,29 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
</configSections>
|
||||
<connectionStrings>
|
||||
<add name="MileageTrakerContext" connectionString="Data Source=localhost;Initial Catalog=MileageTraker;Integrated Security=True;Connect Timeout=60" providerName="System.Data.SqlClient"/>
|
||||
<add name="MileageTrakerContext" connectionString="Data Source=localhost;Initial Catalog=MileageTraker;Integrated Security=True;Connect Timeout=60" providerName="System.Data.SqlClient" />
|
||||
</connectionStrings>
|
||||
<appSettings>
|
||||
<add key="webpages:Version" value="2.0.0.0"/>
|
||||
<add key="PreserveLoginUrl" value="true"/>
|
||||
<add key="ClientValidationEnabled" value="true"/>
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
|
||||
<add key="enableSimpleMembership" value="false"/>
|
||||
<add key="EmailFromAddress" value="Mileage Traker <noreply@ethra.org>"/>
|
||||
<add key="ResetPasswordSubject" value="New Mileage Traker Password Request"/>
|
||||
<add key="ResetPasswordBody" value="Hello {1}, please open this link to set a new password for your Mileage Traker account: {0}"/>
|
||||
<add key="InitializePasswordSubject" value="Initialize Mileage Traker Account"/>
|
||||
<add key="InitializetPasswordBody" value="Hello {1}, welcome to Mileage Traker. Your username is {2}. Please open this link to initialize your password: {0}"/>
|
||||
<add key="webpages:Version" value="2.0.0.0" />
|
||||
<add key="PreserveLoginUrl" value="true" />
|
||||
<add key="ClientValidationEnabled" value="true" />
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
||||
<add key="enableSimpleMembership" value="false" />
|
||||
<add key="EmailFromAddress" value="Mileage Traker <noreply@ethra.org>" />
|
||||
<add key="ResetPasswordSubject" value="New Mileage Traker Password Request" />
|
||||
<add key="ResetPasswordBody" value="Hello {1}, please open this link to set a new password for your Mileage Traker account: {0}" />
|
||||
<add key="InitializePasswordSubject" value="Initialize Mileage Traker Account" />
|
||||
<add key="InitializetPasswordBody" value="Hello {1}, welcome to Mileage Traker. Your username is {2}. Please open this link to initialize your password: {0}" />
|
||||
</appSettings>
|
||||
<system.net>
|
||||
<mailSettings>
|
||||
<smtp deliveryMethod="Network" from="Mileage Traker <roreply@ethra.org>">
|
||||
<network host="localhost"/>
|
||||
<network host="localhost" />
|
||||
</smtp>
|
||||
</mailSettings>
|
||||
</system.net>
|
||||
@@ -35,81 +36,81 @@
|
||||
</system.Web>
|
||||
-->
|
||||
<system.web>
|
||||
<customErrors mode="RemoteOnly"/>
|
||||
<customErrors mode="RemoteOnly" />
|
||||
<compilation debug="true" targetFramework="4.5">
|
||||
<assemblies>
|
||||
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
|
||||
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
|
||||
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
|
||||
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
|
||||
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
|
||||
</assemblies>
|
||||
</compilation>
|
||||
<pages controlRenderingCompatibilityVersion="4.0">
|
||||
<namespaces>
|
||||
<add namespace="System.Web.Helpers"/>
|
||||
<add namespace="System.Web.Mvc"/>
|
||||
<add namespace="System.Web.Mvc.Ajax"/>
|
||||
<add namespace="System.Web.Mvc.Html"/>
|
||||
<add namespace="System.Web.Routing"/>
|
||||
<add namespace="System.Web.WebPages"/>
|
||||
<add namespace="System.Web.Helpers" />
|
||||
<add namespace="System.Web.Mvc" />
|
||||
<add namespace="System.Web.Mvc.Ajax" />
|
||||
<add namespace="System.Web.Mvc.Html" />
|
||||
<add namespace="System.Web.Routing" />
|
||||
<add namespace="System.Web.WebPages" />
|
||||
</namespaces>
|
||||
</pages>
|
||||
<authentication mode="Forms">
|
||||
<forms loginUrl="~/Account/LogIn" timeout="20160"/>
|
||||
<forms loginUrl="~/Account/LogIn" timeout="20160" />
|
||||
</authentication>
|
||||
<machineKey validationKey="BF68567C640A77FF4707F3916A8496366296913AC56E804178D00850B35A47023B91018AC3634ED877C93F1E8B1D504A7785F18BC2B066C1BB2C58D7E86B0A33" decryptionKey="2DCAFFD0B3C8AC300619F5D4BEA046F49AB576D641D156EDDAB4D7A8BE2F2E4B" validation="SHA1" decryption="AES"/>
|
||||
<machineKey validationKey="BF68567C640A77FF4707F3916A8496366296913AC56E804178D00850B35A47023B91018AC3634ED877C93F1E8B1D504A7785F18BC2B066C1BB2C58D7E86B0A33" decryptionKey="2DCAFFD0B3C8AC300619F5D4BEA046F49AB576D641D156EDDAB4D7A8BE2F2E4B" validation="SHA1" decryption="AES" />
|
||||
<membership defaultProvider="CodeFirstMembershipProvider">
|
||||
<providers>
|
||||
<add name="CodeFirstMembershipProvider" type="MileageTraker.Web.DAL.CodeFirstMembershipProvider" connectionStringName="MileageTrakerContext"/>
|
||||
<add name="CodeFirstMembershipProvider" type="MileageTraker.Web.DAL.CodeFirstMembershipProvider" connectionStringName="MileageTrakerContext" />
|
||||
</providers>
|
||||
</membership>
|
||||
<roleManager enabled="true" defaultProvider="CodeFirstRoleProvider">
|
||||
<providers>
|
||||
<add name="CodeFirstRoleProvider" type="MileageTraker.Web.DAL.CodeFirstRoleProvider" connectionStringName="MileageTrakerContext"/>
|
||||
<add name="CodeFirstRoleProvider" type="MileageTraker.Web.DAL.CodeFirstRoleProvider" connectionStringName="MileageTrakerContext" />
|
||||
</providers>
|
||||
</roleManager>
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<validation validateIntegratedModeConfiguration="false"/>
|
||||
<modules runAllManagedModulesForAllRequests="true"/>
|
||||
<validation validateIntegratedModeConfiguration="false" />
|
||||
<modules runAllManagedModulesForAllRequests="true" />
|
||||
</system.webServer>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
|
||||
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
|
||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<log4net>
|
||||
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<file value="Logs\MileageTraker.log"/>
|
||||
<appendToFile value="false"/>
|
||||
<maximumFileSize value="10000KB"/>
|
||||
<maxSizeRollBackups value="250"/>
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
|
||||
<file value="Logs\MileageTraker.log" />
|
||||
<appendToFile value="false" />
|
||||
<maximumFileSize value="10000KB" />
|
||||
<maxSizeRollBackups value="250" />
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %level %logger - %message%newline%exception"/>
|
||||
<conversionPattern value="%date [%thread] %level %logger - %message%newline%exception" />
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="FileAppender"/>
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="FileAppender" />
|
||||
</root>
|
||||
</log4net>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
<parameter value="Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True"/>
|
||||
<parameter value="Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True" />
|
||||
</parameters>
|
||||
</defaultConnectionFactory>
|
||||
</entityFramework>
|
||||
|
||||
+3
-3
@@ -56,9 +56,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\AutoMapper.3.2.1\lib\net40\AutoMapper.Net4.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll</HintPath>
|
||||
<Reference Include="EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ExcelLibrary, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ExcelLibrary.1.2011.7.30\lib\ExcelLibrary.dll</HintPath>
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AutoMapper" version="3.2.1" targetFramework="net40" />
|
||||
<package id="EntityFramework" version="4.3.1" requireReinstallation="True" />
|
||||
<package id="EntityFramework" version="5.0.0" targetFramework="net45" />
|
||||
<package id="ExcelLibrary" version="1.2011.7.30" />
|
||||
<package id="FontAwesome" version="4.0.3.1" targetFramework="net40" />
|
||||
<package id="JonSkeet.MiscUtil" version="0.1" targetFramework="net40" />
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
</configSections>
|
||||
</configuration>
|
||||
@@ -1,5 +0,0 @@
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
</configSections>
|
||||
</configuration>
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -1,52 +0,0 @@
|
||||
-----------------------------------------------------------------------------------------
|
||||
Entity Framework 5 Recommended for .NET Framework 4.5 Projects
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
You have installed EF 4.3 in a project that targets .NET Framework 4.5.
|
||||
|
||||
There are some known issues using EF 4.x in a .NET 4.5 project.
|
||||
|
||||
|
||||
We recommend installing a pre-release version of EF 5, which is designed to work with .NET 4.5
|
||||
|
||||
1) Open package manager console
|
||||
Tools -> Library Package Manager -> Package Manager Console
|
||||
|
||||
2) Use the following command to install the latest pre-release package
|
||||
Install-Package EntityFramework -IncludePreRelease
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
Known Issues with Entity Framework 4.x and .NET Framework 4.5
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
Entity Framework 4.1 thru 4.3 included additional data annotations in the
|
||||
System.ComponentModel.DataAnnotations namespace in the EntityFramework assembly.
|
||||
In .NET 4.5 these annotations were moved to be part of the .NET Framework in the
|
||||
System.ComponentModel.DataAnnotations.Schema namespace of the
|
||||
System.ComponentModel.DataAnnotations.dll assembly. If you are using EF 4.x and targeting
|
||||
.NET 4.5 this results in two data annotations with the same name in different assemblies.
|
||||
Because the annotations in the .NET Framework are in a different namespace we were not
|
||||
able to use type forwarding to avoid this conflict.
|
||||
|
||||
It is possible to use EF 4.x on .NET 4.5 but we recommend using the latest pre-release
|
||||
version of EF 5. If you are not using the affected data annotations there is no impact
|
||||
on your code. If you are using the data annotations in a C# project you can use the extern
|
||||
modifier to ensure your code uses the annotations from EntityFramework.dll
|
||||
(http://msdn.microsoft.com/en-us/library/e59b22c5(v=VS.80).aspx). If you use the new
|
||||
annotations from the System.ComponentModel.DataAnnotations.dll assembly in .NET 4.5
|
||||
they will not be processed by Code First.
|
||||
|
||||
The affected annotations are:
|
||||
- Column
|
||||
- ComplexType
|
||||
- DatabaseGenerated
|
||||
- DatabaseGeneratedOption
|
||||
- ForeignKey
|
||||
- InverseProperty
|
||||
- MaxLength
|
||||
- MinLength
|
||||
- NotMapped
|
||||
- Table
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,493 +0,0 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
$InitialDatabase = '0'
|
||||
|
||||
$installPath = $args[0]
|
||||
$knownExceptions = @(
|
||||
'System.Data.Entity.Migrations.Infrastructure.MigrationsException',
|
||||
'System.Data.Entity.Migrations.Infrastructure.AutomaticMigrationsDisabledException',
|
||||
'System.Data.Entity.Migrations.Infrastructure.AutomaticDataLossException'
|
||||
)
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Enables Code First Migrations in a project.
|
||||
|
||||
.DESCRIPTION
|
||||
Enables Migrations by scaffolding a migrations configuration class in the project. If the
|
||||
target database was created by an initializer, an initial migration will be created (unless
|
||||
automatic migrations are enabled via the EnableAutomaticMigrations parameter).
|
||||
|
||||
.PARAMETER EnableAutomaticMigrations
|
||||
Specifies whether automatic migrations will be enabled in the scaffolded migrations configuration.
|
||||
If ommitted, automatic migrations will be disabled.
|
||||
|
||||
.PARAMETER ProjectName
|
||||
Specifies the project that the scaffolded migrations configuration class will
|
||||
be added to. If omitted, the default project selected in package manager
|
||||
console is used.
|
||||
|
||||
.PARAMETER Force
|
||||
Specifies that the migrations configuration be overwritten when running more
|
||||
than once for a given project.
|
||||
#>
|
||||
function Enable-Migrations
|
||||
{
|
||||
[CmdletBinding(DefaultParameterSetName = 'ProjectName')]
|
||||
param (
|
||||
[alias("Auto")]
|
||||
[switch] $EnableAutomaticMigrations,
|
||||
[string] $ProjectName,
|
||||
[switch] $Force
|
||||
)
|
||||
|
||||
try
|
||||
{
|
||||
$commands = New-MigrationsCommandsNoConfiguration $ProjectName
|
||||
$commands.EnableMigrations($EnableAutomaticMigrations, $Force)
|
||||
}
|
||||
catch [Exception]
|
||||
{
|
||||
$exception = $_.Exception
|
||||
$exceptionType = $exception.GetType()
|
||||
|
||||
if ($exceptionType.FullName -eq 'System.Data.Entity.Migrations.Design.ToolingException')
|
||||
{
|
||||
if ($knownExceptions -notcontains $exception.InnerType)
|
||||
{
|
||||
Write-Host $exception.InnerStackTrace
|
||||
}
|
||||
}
|
||||
elseif (!(Test-TypeInherits $exceptionType 'System.Data.Entity.Migrations.Infrastructure.MigrationsException'))
|
||||
{
|
||||
Write-Host $exception
|
||||
}
|
||||
|
||||
throw $exception.Message
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Scaffolds a migration script for any pending model changes.
|
||||
|
||||
.DESCRIPTION
|
||||
Scaffolds a new migration script and adds it to the project.
|
||||
|
||||
.PARAMETER Name
|
||||
Specifies the name of the custom script.
|
||||
|
||||
.PARAMETER Force
|
||||
Specifies that the migration user code be overwritten when re-scaffolding an
|
||||
existing migration.
|
||||
|
||||
.PARAMETER ProjectName
|
||||
Specifies the project that contains the migration configuration type to be
|
||||
used. If ommitted, the default project selected in package manager console
|
||||
is used.
|
||||
|
||||
.PARAMETER StartUpProjectName
|
||||
Specifies the configuration file to use for named connection strings. If
|
||||
omitted, the specified project's configuration file is used.
|
||||
|
||||
.PARAMETER ConfigurationTypeName
|
||||
Specifies the migrations configuration to use. If omitted, migrations will
|
||||
attempt to locate a single migrations configuration type in the target
|
||||
project.
|
||||
|
||||
.PARAMETER ConnectionStringName
|
||||
Specifies the name of a connection string to use from the application's
|
||||
configuration file.
|
||||
|
||||
.PARAMETER ConnectionString
|
||||
Specifies the the connection string to use. If omitted, the context's
|
||||
default connection will be used.
|
||||
|
||||
.PARAMETER ConnectionProviderName
|
||||
Specifies the provider invariant name of the connection string.
|
||||
|
||||
.PARAMETER IgnoreChanges
|
||||
Scaffolds an empty migration ignoring any pending changes detected in the current model.
|
||||
This can be used to create an initial, empty migration to enable Migrations for an existing
|
||||
database. N.B. Doing this assumes that the target database schema is compatible with the
|
||||
current model.
|
||||
|
||||
#>
|
||||
function Add-Migration
|
||||
{
|
||||
[CmdletBinding(DefaultParameterSetName = 'ConnectionStringName')]
|
||||
param (
|
||||
[parameter(Position = 0,
|
||||
Mandatory = $true)]
|
||||
[string] $Name,
|
||||
[switch] $Force,
|
||||
[string] $ProjectName,
|
||||
[string] $StartUpProjectName,
|
||||
[string] $ConfigurationTypeName,
|
||||
[parameter(ParameterSetName = 'ConnectionStringName')]
|
||||
[string] $ConnectionStringName,
|
||||
[parameter(ParameterSetName = 'ConnectionStringAndProviderName',
|
||||
Mandatory = $true)]
|
||||
[string] $ConnectionString,
|
||||
[parameter(ParameterSetName = 'ConnectionStringAndProviderName',
|
||||
Mandatory = $true)]
|
||||
[string] $ConnectionProviderName,
|
||||
[switch] $IgnoreChanges)
|
||||
|
||||
try
|
||||
{
|
||||
$commands = New-MigrationsCommands $ProjectName $StartUpProjectName $ConfigurationTypeName $ConnectionStringName $ConnectionString $ConnectionProviderName
|
||||
$commands.AddMigration($Name, $Force, $IgnoreChanges)
|
||||
}
|
||||
catch [Exception]
|
||||
{
|
||||
$exception = $_.Exception
|
||||
$exceptionType = $exception.GetType()
|
||||
|
||||
if ($exceptionType.FullName -eq 'System.Data.Entity.Migrations.Design.ToolingException')
|
||||
{
|
||||
if ($knownExceptions -notcontains $exception.InnerType)
|
||||
{
|
||||
Write-Host $exception.InnerStackTrace
|
||||
}
|
||||
}
|
||||
elseif (!(Test-TypeInherits $exceptionType 'System.Data.Entity.Migrations.Infrastructure.MigrationsException'))
|
||||
{
|
||||
Write-Host $exception
|
||||
}
|
||||
|
||||
throw $exception.Message
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Applies any pending migrations to the database.
|
||||
|
||||
.DESCRIPTION
|
||||
Updates the database to the current model by applying pending migrations.
|
||||
|
||||
.PARAMETER SourceMigration
|
||||
Only valid with -Script. Specifies the name of a particular migration to use
|
||||
as the update's starting point. If ommitted, the last applied migration in
|
||||
the database will be used.
|
||||
|
||||
.PARAMETER TargetMigration
|
||||
Specifies the name of a particular migration to update the database to. If
|
||||
ommitted, the current model will be used.
|
||||
|
||||
.PARAMETER Script
|
||||
Generate a SQL script rather than executing the pending changes directly.
|
||||
|
||||
.PARAMETER Force
|
||||
Specifies that data loss is acceptable during automatic migration of the
|
||||
database.
|
||||
|
||||
.PARAMETER ProjectName
|
||||
Specifies the project that contains the migration configuration type to be
|
||||
used. If ommitted, the default project selected in package manager console
|
||||
is used.
|
||||
|
||||
.PARAMETER StartUpProjectName
|
||||
Specifies the configuration file to use for named connection strings. If
|
||||
omitted, the specified project's configuration file is used.
|
||||
|
||||
.PARAMETER ConfigurationTypeName
|
||||
Specifies the migrations configuration to use. If omitted, migrations will
|
||||
attempt to locate a single migrations configuration type in the target
|
||||
project.
|
||||
|
||||
.PARAMETER ConnectionStringName
|
||||
Specifies the name of a connection string to use from the application's
|
||||
configuration file.
|
||||
|
||||
.PARAMETER ConnectionString
|
||||
Specifies the the connection string to use. If omitted, the context's
|
||||
default connection will be used.
|
||||
|
||||
.PARAMETER ConnectionProviderName
|
||||
Specifies the provider invariant name of the connection string.
|
||||
#>
|
||||
function Update-Database
|
||||
{
|
||||
[CmdletBinding(DefaultParameterSetName = 'ConnectionStringName')]
|
||||
param (
|
||||
[string] $SourceMigration,
|
||||
[string] $TargetMigration,
|
||||
[switch] $Script,
|
||||
[switch] $Force,
|
||||
[string] $ProjectName,
|
||||
[string] $StartUpProjectName,
|
||||
[string] $ConfigurationTypeName,
|
||||
[parameter(ParameterSetName = 'ConnectionStringName')]
|
||||
[string] $ConnectionStringName,
|
||||
[parameter(ParameterSetName = 'ConnectionStringAndProviderName',
|
||||
Mandatory = $true)]
|
||||
[string] $ConnectionString,
|
||||
[parameter(ParameterSetName = 'ConnectionStringAndProviderName',
|
||||
Mandatory = $true)]
|
||||
[string] $ConnectionProviderName)
|
||||
|
||||
# TODO: If possible, convert this to a ParameterSet
|
||||
if ($SourceMigration -and !$script)
|
||||
{
|
||||
throw '-SourceMigration can only be specified with -Script.'
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$commands = New-MigrationsCommands $ProjectName $StartUpProjectName $ConfigurationTypeName $ConnectionStringName $ConnectionString $ConnectionProviderName
|
||||
$commands.UpdateDatabase($SourceMigration, $TargetMigration, $Script, $Force)
|
||||
}
|
||||
catch [Exception]
|
||||
{
|
||||
$exception = $_.Exception
|
||||
$exceptionType = $exception.GetType()
|
||||
|
||||
if ($exceptionType.FullName -eq 'System.Data.Entity.Migrations.Design.ToolingException')
|
||||
{
|
||||
if ($knownExceptions -notcontains $exception.InnerType)
|
||||
{
|
||||
Write-Host $exception.InnerStackTrace
|
||||
}
|
||||
}
|
||||
elseif (!(Test-TypeInherits $exceptionType 'System.Data.Entity.Migrations.Infrastructure.MigrationsException'))
|
||||
{
|
||||
Write-Host $exception
|
||||
}
|
||||
|
||||
throw $exception.Message
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Displays the migrations that have been applied to the target database.
|
||||
|
||||
.DESCRIPTION
|
||||
Displays the migrations that have been applied to the target database.
|
||||
|
||||
.PARAMETER ProjectName
|
||||
Specifies the project that contains the migration configuration type to be
|
||||
used. If ommitted, the default project selected in package manager console
|
||||
is used.
|
||||
|
||||
.PARAMETER StartUpProjectName
|
||||
Specifies the configuration file to use for named connection strings. If
|
||||
omitted, the specified project's configuration file is used.
|
||||
|
||||
.PARAMETER ConfigurationTypeName
|
||||
Specifies the migrations configuration to use. If omitted, migrations will
|
||||
attempt to locate a single migrations configuration type in the target
|
||||
project.
|
||||
|
||||
.PARAMETER ConnectionStringName
|
||||
Specifies the name of a connection string to use from the application's
|
||||
configuration file.
|
||||
|
||||
.PARAMETER ConnectionString
|
||||
Specifies the the connection string to use. If omitted, the context's
|
||||
default connection will be used.
|
||||
|
||||
.PARAMETER ConnectionProviderName
|
||||
Specifies the provider invariant name of the connection string.
|
||||
#>
|
||||
function Get-Migrations
|
||||
{
|
||||
[CmdletBinding(DefaultParameterSetName = 'ConnectionStringName')]
|
||||
param (
|
||||
[string] $ProjectName,
|
||||
[string] $StartUpProjectName,
|
||||
[string] $ConfigurationTypeName,
|
||||
[parameter(ParameterSetName = 'ConnectionStringName')]
|
||||
[string] $ConnectionStringName,
|
||||
[parameter(ParameterSetName = 'ConnectionStringAndProviderName',
|
||||
Mandatory = $true)]
|
||||
[string] $ConnectionString,
|
||||
[parameter(ParameterSetName = 'ConnectionStringAndProviderName',
|
||||
Mandatory = $true)]
|
||||
[string] $ConnectionProviderName)
|
||||
|
||||
try
|
||||
{
|
||||
$commands = New-MigrationsCommands $ProjectName $StartUpProjectName $ConfigurationTypeName $ConnectionStringName $ConnectionString $ConnectionProviderName
|
||||
$commands.GetMigrations()
|
||||
}
|
||||
catch [Exception]
|
||||
{
|
||||
$exception = $_.Exception
|
||||
$exceptionType = $exception.GetType()
|
||||
|
||||
if ($exceptionType.FullName -eq 'System.Data.Entity.Migrations.Design.ToolingException')
|
||||
{
|
||||
if ($knownExceptions -notcontains $exception.InnerType)
|
||||
{
|
||||
Write-Host $exception.InnerStackTrace
|
||||
}
|
||||
}
|
||||
elseif (!(Test-TypeInherits $exceptionType 'System.Data.Entity.Migrations.Infrastructure.MigrationsException'))
|
||||
{
|
||||
Write-Host $exception
|
||||
}
|
||||
|
||||
throw $exception.Message
|
||||
}
|
||||
}
|
||||
|
||||
function New-MigrationsCommandsNoConfiguration($ProjectName)
|
||||
{
|
||||
$project = Get-MigrationsProject $ProjectName
|
||||
|
||||
Build-Project $project
|
||||
|
||||
Load-EntityFramework
|
||||
|
||||
try
|
||||
{
|
||||
return New-Object 'System.Data.Entity.Migrations.MigrationsCommands' @(
|
||||
$project,
|
||||
$project,
|
||||
$null,
|
||||
$null,
|
||||
$null,
|
||||
$null,
|
||||
$PSCmdlet )
|
||||
}
|
||||
catch [System.Management.Automation.MethodInvocationException]
|
||||
{
|
||||
throw $_.Exception.InnerException
|
||||
}
|
||||
}
|
||||
|
||||
function New-MigrationsCommands($ProjectName, $StartUpProjectName, $ConfigurationTypeName, $ConnectionStringName, $ConnectionString, $ConnectionProviderName)
|
||||
{
|
||||
$project = Get-MigrationsProject $ProjectName
|
||||
$startUpProject = Get-MigrationsStartUpProject $StartUpProjectName
|
||||
|
||||
Build-Project $project
|
||||
Build-Project $startUpProject
|
||||
|
||||
Load-EntityFramework
|
||||
|
||||
try
|
||||
{
|
||||
return New-Object 'System.Data.Entity.Migrations.MigrationsCommands' @(
|
||||
$project,
|
||||
$startUpProject,
|
||||
$ConfigurationTypeName,
|
||||
$ConnectionStringName,
|
||||
$ConnectionString,
|
||||
$ConnectionProviderName,
|
||||
$PSCmdlet )
|
||||
}
|
||||
catch [System.Management.Automation.MethodInvocationException]
|
||||
{
|
||||
throw $_.Exception.InnerException
|
||||
}
|
||||
}
|
||||
|
||||
function Get-MigrationsProject($name)
|
||||
{
|
||||
if ($name)
|
||||
{
|
||||
return Get-SingleProject $name
|
||||
}
|
||||
|
||||
$project = Get-Project
|
||||
|
||||
Write-Verbose ('Using NuGet project ''' + $project.Name + '''.')
|
||||
|
||||
return $project
|
||||
}
|
||||
|
||||
function Get-MigrationsStartUpProject($name)
|
||||
{
|
||||
if ($name)
|
||||
{
|
||||
return Get-SingleProject $name
|
||||
}
|
||||
|
||||
$startupProjectPaths = $DTE.Solution.SolutionBuild.StartupProjects
|
||||
|
||||
if (!$startupProjectPaths)
|
||||
{
|
||||
throw 'No start-up project found. Please use the -StartupProject parameter.'
|
||||
}
|
||||
if ($startupProjectPaths.Length -gt 1)
|
||||
{
|
||||
throw 'More than one start-up project found. Please use the -StartUpProject parameter.'
|
||||
}
|
||||
|
||||
$startupProjectPath = $startupProjectPaths[0]
|
||||
|
||||
if (!(Split-Path -IsAbsolute $startupProjectPath))
|
||||
{
|
||||
$solutionPath = Split-Path $DTE.Solution.Properties.Item('Path').Value
|
||||
$startupProjectPath = Join-Path $solutionPath $startupProjectPath -Resolve
|
||||
}
|
||||
|
||||
$startupProject = $DTE.Solution.Projects | ?{
|
||||
$fullName = $_.FullName
|
||||
|
||||
if ($fullName -and $fullName.EndsWith('\'))
|
||||
{
|
||||
$fullName = $fullName.Substring(0, $fullName.Length - 1)
|
||||
}
|
||||
|
||||
return $fullName -eq $startupProjectPath
|
||||
}
|
||||
|
||||
Write-Verbose ('Using StartUp project ''' + $startupProject.Name + '''.')
|
||||
|
||||
return $startupProject
|
||||
}
|
||||
|
||||
function Get-SingleProject($name)
|
||||
{
|
||||
$project = Get-Project $name
|
||||
|
||||
if ($project -is [array])
|
||||
{
|
||||
throw "More than one project '$name' was found. Specify the full name of the one to use."
|
||||
}
|
||||
|
||||
return $project
|
||||
}
|
||||
|
||||
function Load-EntityFramework()
|
||||
{
|
||||
[System.AppDomain]::CurrentDomain.SetShadowCopyFiles()
|
||||
[System.Reflection.Assembly]::LoadFrom((Join-Path $installPath 'lib\net40\EntityFramework.dll')) | Out-Null
|
||||
[System.Reflection.Assembly]::LoadFrom((Join-Path $installPath 'tools\EntityFramework.PowerShell.dll')) | Out-Null
|
||||
}
|
||||
|
||||
function Build-Project($project)
|
||||
{
|
||||
$configuration = $DTE.Solution.SolutionBuild.ActiveConfiguration.Name
|
||||
|
||||
$DTE.Solution.SolutionBuild.BuildProject($configuration, $project.UniqueName, $true)
|
||||
|
||||
if ($DTE.Solution.SolutionBuild.LastBuildInfo)
|
||||
{
|
||||
throw 'The project ''' + $project.Name + ''' failed to build.'
|
||||
}
|
||||
}
|
||||
|
||||
function Test-TypeInherits($type, $baseTypeName)
|
||||
{
|
||||
if ($type.FullName -eq $baseTypeName)
|
||||
{
|
||||
return $true
|
||||
}
|
||||
|
||||
$baseType = $type.BaseType
|
||||
|
||||
if ($baseType)
|
||||
{
|
||||
return Test-TypeInherits $baseType $baseTypeName
|
||||
}
|
||||
|
||||
return $false
|
||||
}
|
||||
|
||||
Export-ModuleMember @( 'Enable-Migrations', 'Add-Migration', 'Update-Database', 'Get-Migrations' ) -Variable 'InitialDatabase'
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
param($installPath, $toolsPath, $package, $project)
|
||||
|
||||
if ([System.AppDomain]::CurrentDomain.GetAssemblies() | ?{ $_.GetName().Name -eq 'EntityFramework' })
|
||||
{
|
||||
Write-Warning 'There is already a version of EntityFramework.dll loaded. You may need to restart Visual Studio for the commands to work properly.'
|
||||
}
|
||||
|
||||
if (Get-Module | ?{ $_.Name -eq 'EntityFramework' })
|
||||
{
|
||||
Remove-Module 'EntityFramework'
|
||||
}
|
||||
|
||||
Import-Module (Join-Path $toolsPath 'EntityFramework.psd1') -ArgumentList $installPath
|
||||
@@ -1,36 +0,0 @@
|
||||
param($installPath, $toolsPath, $package, $project)
|
||||
|
||||
$invoker = @"
|
||||
public class ConnectionFactoryConfiguratorInvoker
|
||||
{
|
||||
public static void Invoke(string assemblyPath, object project)
|
||||
{
|
||||
var appDomain = System.AppDomain.CreateDomain(
|
||||
"EntityFramework.PowerShell",
|
||||
null,
|
||||
new System.AppDomainSetup { ShadowCopyFiles = "true" });
|
||||
|
||||
appDomain.CreateInstanceFrom(
|
||||
assemblyPath,
|
||||
"System.Data.Entity.ConnectionFactoryConfig.ConnectionFactoryConfigurator",
|
||||
false,
|
||||
0,
|
||||
null,
|
||||
new object[] { project },
|
||||
null,
|
||||
null);
|
||||
|
||||
System.AppDomain.Unload(appDomain);
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
$version = (new-object System.Runtime.Versioning.FrameworkName($project.Properties.Item("TargetFrameworkMoniker").Value)).Version
|
||||
|
||||
if ($version -ge (new-object System.Version(4, 5)))
|
||||
{
|
||||
$dte.ItemOperations.OpenFile((Join-Path $toolsPath 'EF4.3on.NET4.5Readme.txt'))
|
||||
}
|
||||
|
||||
Add-Type -TypeDefinition $invoker
|
||||
[ConnectionFactoryConfiguratorInvoker]::Invoke((Join-Path $toolsPath "EntityFramework.PowerShell.dll"), $project)
|
||||
Binary file not shown.
Reference in New Issue
Block a user