BIML GetDropAndCreateDdl creating incorrect lengths for datatypes - tsql

When I use GetDropAndCreateDdl to generate CREATE scripts for tables, I get datatypes for columns that are different than what the datatypes actually are.
This results in a package validation error that "the error output has properties that do not match the properties of its corresponding data source column" and a validation status of "VS_NEEDSNEWMETADATA".
If I right-click the connection source, select Show Advanced Editor, and take a look at the Column Mappings, I can see that [Column1] in the Available External Columns list has a different Length than the datatype that was generated in the GetDropAndCreateDdl. I can delete and re-create the metadata mappings, but that is not a viable solution since there are many dataflow tasks.
How do I get GetDropAndCreateDdl to create the correct datatypes with correct lengths?
I am using ImportDB to get the list of tables, metadata, etc.
Environment.biml
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OdbcConnection Name="OdbcSrc_DV" ConnectionString="Dsn=Source-32bit-test;" />
<OleDbConnection Name="OleDbDst_Staging" ConnectionString="Provider=SQLNCLI11;Server=SQL-DEV;Initial Catalog=Source_Staging;Integrated Security=SSPI;" />
</Connections>
<Databases>
<Database Name="Source" ConnectionName="OdbcSrc_DV" />
<Database Name="Source_Staging" ConnectionName="OleDbDst_Staging" />
</Databases>
<Schemas>
<Schema Name="dbo" DatabaseName="Source" />
<Schema Name="dbo" DatabaseName="Source_Staging" />
</Schemas>
</Biml>
CreateTableMetadata.biml
<## import namespace="System.Data" #>
<## import namespace="Varigence.Biml.CoreLowerer.SchemaManagement" #>
<#
var sourceConnection = RootNode.DbConnections["OdbcSrc_DV"];
var importResult = sourceConnection.ImportDB("", "", ImportOptions.ExcludeForeignKey | ImportOptions.ExcludeColumnDefault | ImportOptions.ExcludeViews);
var tableNamesToImport = new List<string>() { "Test_Table" };
#>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Tables>
<# foreach (var table in importResult.TableNodes.Where(item => tableNamesToImport.Contains(item.Name)).OrderBy(item => item.Name)) { #>
<Table Name="<#=table.Name#>" SchemaName="Source.dbo">
<Columns>
<#=table.Columns.GetBiml()#>
</Columns>
<Annotations>
<Annotation AnnotationType="Tag" Tag="SourceSchemaQualifiedName"><#=table.SchemaQualifiedName#></Annotation>
</Annotations>
</Table>
<# } #>
</Tables>
</Biml>
DeployTargetTables.biml
<## template tier="2" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package Name="MasterTableDeploy" ConstraintMode="Parallel">
<Tasks>
<# foreach (var table in RootNode.Tables) { #>
<ExecuteSQL Name="SQL CREATE <#=table.Name#>" ConnectionName="OleDbDst_Staging">
<DirectInput><#=table.GetDropAndCreateDdl()#></DirectInput>
</ExecuteSQL>
<# } #>
</Tasks>
</Package>
</Packages>
</Biml>
CreateLoadPackages.biml
<## template tier="2" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package Name="Copy Data" ConstraintMode="Parallel">
<Tasks>
<# foreach (var table in RootNode.Tables) { #>
<ExecuteSQL Name="SQL TRUNCATE <#=table.Name#>" ConnectionName="OleDbDst_Staging">
<DirectInput>TRUNCATE TABLE <#=table.Name#></DirectInput>
</ExecuteSQL>
<Dataflow Name="DFT LOAD <#=table.Schema.Name#>_<#=table.Name#>">
<PrecedenceConstraints>
<Inputs>
<Input OutputPathName="SQL TRUNCATE <#=table.Name#>.Output" />
</Inputs>
</PrecedenceConstraints>
<Transformations>
<OdbcSource Name="ODBC_SRC <#=table.Name#>" Connection="OdbcSrc_DV">
<DirectInput>SELECT <#=table.GetColumnList()#> FROM <#=table.GetTag("SourceSchemaQualifiedName")#></DirectInput>
</OdbcSource>
<OleDbDestination Name="ODBC_DST <#=table.Name#>" ConnectionName="OleDbDst_Staging">
<TableOutput TableName="<#=table.ScopedName#>" />
</OleDbDestination>
</Transformations>
</Dataflow>
<# } #>
</Tasks>
</Package>
</Packages>
</Biml>
Here is the script that gets created from the ODBC source -
And here are the results from INFORMATION_SCHEMA.COLUMNS for the same table -

Have you tried using the newer method: GetDatabaseSchema? I've found it to be much more reliable across different connection types.
http://www.cathrinewilhelmsen.net/2015/07/12/biml-extension-methods-getdatabaseschema/

Related

Filter (xml-)Data with Where-Object count ... in PowerShell

I have the following code in PowerShell:
[xml]$Xml = #"
<?xml version="1.0" encoding="utf-8"?>
<Sequences>
<Sequence>
<SequenceName>Sequence-A</SequenceName>
<SequencePackages>
<Package>
<PackageFolder>Package-A</PackageFolder>
<PackageActive>False</PackageActive>
</Package>
<Package>
<PackageFolder>Package-B</PackageFolder>
</Package>
</SequencePackages>
</Sequence>
<Sequence>
<SequenceName>Sequence-B</SequenceName>
<SequencePackages>
<Package>
<PackageFolder>Package-C</PackageFolder>
<PackageMeta>
<PackageStart>2019-07-23T18:53:58.392+02:00</PackageStart>
<PackageEnd>2019-07-23T18:53:58.392+02:00</PackageEnd>
</PackageMeta>
</Package>
<Package>
<PackageFolder>Package-D</PackageFolder>
<PackageMeta>
<PackageStart>2019-07-23T18:53:58.407+02:00</PackageStart>
<PackageEnd>2019-07-23T18:53:58.407+02:00</PackageEnd>
</PackageMeta>
</Package>
</SequencePackages>
</Sequence>
</Sequences>
"#
Clear-Host
$Sequences = $Xml.Sequences.Sequence | Where-Object ...
$Sequences
As you see, I load XML-Data and then I want to filter it with "Where-Object".
In the XML, we see 2 Sequence-nodes containing 2 package-nodes each.
I want to select those "Sequence" node(s), that have:
At least one Active Package. A Package is Active, when there is ( NO node ) OR ( IS TRUE )
(In the example Package-A is not active)
At least one package has no end-time (Attribute "PackageEnd")
In this example, the result of the query should be "Sequence-A", because it does have a package, which does NOT contain the attribute "PackageActive" and both packages have no end-time (Attribute "PackageEnd" is not set).
Ideally I am looking for a one-liner ...
Thank you in advance for your support!
EDIT:
I did add further examples for clarification ...
[xml]$Xml = #"
<?xml version="1.0" encoding="utf-8"?>
<Sequences>
<Sequence>
<SequenceName>Sequence-A</SequenceName>
<SequencePackages>
<Package>
<PackageFolder>Package-A</PackageFolder>
<PackageActive>False</PackageActive>
</Package>
<Package>
<PackageFolder>Package-B</PackageFolder>
</Package>
</SequencePackages>
</Sequence>
<Sequence>
<SequenceName>Sequence-B</SequenceName>
<SequencePackages>
<Package>
<PackageFolder>Package-C</PackageFolder>
<PackageMeta>
<PackageEnd>2019-07-23T18:53:58.392+02:00</PackageEnd>
</PackageMeta>
</Package>
<Package>
<PackageFolder>Package-D</PackageFolder>
<PackageMeta>
<PackageEnd>2019-07-23T18:53:58.407+02:00</PackageEnd>
</PackageMeta>
</Package>
</SequencePackages>
</Sequence>
<Sequence>
<SequenceName>Sequence-C</SequenceName>
<SequencePackages>
<Package>
<PackageFolder>Package-E</PackageFolder>
<PackageActive>False</PackageActive>
</Package>
<Package>
<PackageFolder>Package-F</PackageFolder>
<PackageMeta>
<PackageEnd>2019-07-23T18:53:58.407+02:00</PackageEnd>
</PackageMeta>
</Package>
</SequencePackages>
</Sequence>
<Sequence>
<SequenceName>Sequence-D</SequenceName>
<SequencePackages>
<Package>
<PackageFolder>Package-G</PackageFolder>
<PackageActive>True</PackageActive>
</Package>
<Package>
<PackageFolder>Package-H</PackageFolder>
</Package>
</SequencePackages>
</Sequence>
</Sequences>
"#
Sequence-A should be selected. Package-A won't be processed, but Package-B does NOT contain a PackageEnd-node.
Sequence-B should NOT be selected. Both packages contain a PackageEnd-node.
Sequence-C should NOT be selected. Package-E is NOT Active and Package-F contains a PackageEnd-node.
Sequence-D should be selected. Package-G is Active and Package-H also. Both Packages do not contain a PackageEnd-node.
You should be able to pipe this to a where-object filter pretty easily. I used the second xml example. Maybe the xml could be designed better. Packagemeta doesn't show up under $xml.sequences.sequence.sequencepackages.package, unless you pipe it to format-list. I only put the outer foreach in side the & { } so you can pipe from it.
& {
foreach ($s in $xml.sequences.sequence) {
foreach ($p in $s.sequencepackages.package) {
[pscustomobject] #{
sequencename = $s.sequencename
packagefolder = $p.packagefolder
packageactive = $p.packageactive
packageend = $p.packagemeta.packageend
}
}
}
}
sequencename packagefolder packageactive packageend
------------ ------------- ------------- ----------
Sequence-A Package-A False
Sequence-A Package-B
Sequence-B Package-C 2019-07-23T18:53:58.392+02:00
Sequence-B Package-D 2019-07-23T18:53:58.407+02:00
Sequence-C Package-E False
Sequence-C Package-F 2019-07-23T18:53:58.407+02:00
Sequence-D Package-G True
Sequence-D Package-H
The following one-liner seems to be the solution:
$Sequences = $Xml.Sequences.SelectNodes( "//Sequence[.//Package[(./PackageActive/text()='True' or not(./PackageActive)) and not(.//PackageEnd)]]" )

BIML Nested For loop Container

I'm trying to nest a forloop container within another. I keep getting error that child element is not allowed.
How do I nest for loop?
<ForLoop Name="For loop for Year">
<PrecedenceConstraints>
<Inputs>
<Input OutputPathName="Find count of rows.Output" SsisName="No data exist" PathAnnotation="ConstraintName" EvaluationOperation="Expression" EvaluationValue="Success" Expression="#[User::CountRows]==0" />
</Inputs>
</PrecedenceConstraints>
<InitializerExpression>#StartYear</InitializerExpression>
<LoopTestExpression><![CDATA[#StartYear <= #EndYear]]></LoopTestExpression>
<CountingExpression><![CDATA[#StartYear = #StartYear + 1]]></CountingExpression>
<ForLoop Name="For loop for Month">
<InitializerExpression>#StartMonth</InitializerExpression>
<LoopTestExpression><![CDATA[#StartMonth <= #EndMonth]]></LoopTestExpression>
<CountingExpression>#StartMonth = #StartMonth + 1</CountingExpression>
</ForLoop>
</ForLoop>
A ForLoop is a member of the Tasks collection. You have specified that your inner ForLoop is a member of the outer ForLoop. Instead, it should be a member of the outer ForLoop's Task collection.
Thus
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package Name="so_46415142">
<Variables>
<Variable Name="StartYear" DataType="Int32">2014</Variable>
<Variable Name="EndYear" DataType="Int32">2014</Variable>
<Variable Name="StartMonth" DataType="Int32">1</Variable>
<Variable Name="EndMonth" DataType="Int32">6</Variable>
</Variables>
<Tasks>
<ForLoop Name="For loop for Year">
<!--
<PrecedenceConstraints>
<Inputs>
<Input OutputPathName="Find count of rows.Output" SsisName="No data exist" PathAnnotation="ConstraintName" EvaluationOperation="Expression" EvaluationValue="Success" Expression="#[User::CountRows]==0" />
</Inputs>
</PrecedenceConstraints>
-->
<InitializerExpression>#StartYear</InitializerExpression>
<LoopTestExpression><![CDATA[#StartYear <= #EndYear]]></LoopTestExpression>
<CountingExpression><![CDATA[#StartYear = #StartYear + 1]]></CountingExpression>
<Tasks>
<ForLoop Name="For loop for Month">
<InitializerExpression>#StartMonth</InitializerExpression>
<LoopTestExpression><![CDATA[#StartMonth <= #EndMonth]]></LoopTestExpression>
<CountingExpression>#StartMonth = #StartMonth + 1</CountingExpression>
</ForLoop>
</Tasks>
</ForLoop>
</Tasks>
</Package>
</Packages>
</Biml>

SQLite EF6 error

Im using win10, vs2017.
I created a new project, then added nuget "System.Data.SQLite".
Next, I installed "sqlite-netFx46-setup-bundle-x86-2015-1.0.105.2.exe" from system.data.sqlite.org with fullInstall options and checkboxes.
I rebooted the PC.
Then in the Visual Studio Server Explorer, I connected a new SQLite Database.
Further added "ADO .Net Entity Date Model", added Entity and used "Generate DB from model"
Im getting this error:
App.config:
<?xml version="1.0" encoding="utf-8"?>
<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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<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>
<connectionStrings>
<add name="mainEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite.EF6;provider connection string='data source="C:\Users\User\Documents\Visual Studio Projects\DeleteThis\Test.db";version=3'" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
SSDLToSQL10.tt:
<#
//---------------------------------------------------------------------
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
//---------------------------------------------------------------------
// This T4 template generates T-SQL from an instance of
// System.Data.Metadata.Edm.StoreItemCollection, an object representation
// of the SSDL. This T-SQL is compatible with SQL 2012, 2008, 2005, CE, and Azure databases.
//---------------------------------------------------------------------
// Note: We will resolve all paths in assembly directives at runtime, taking
// macros and environment variables into account (e.g. $(ProjectDir), $(DevEnvDir) etc.)
#>
<## assembly name="System.Core" #>
<## assembly name="$(DevEnvDir)..\IDE\Microsoft.Data.Entity.Design.DatabaseGeneration.dll"#>
<## assembly name="$(DevEnvDir)..\IDE\EntityFramework.dll"#>
<## assembly name="$(DevEnvDir)..\IDE\EntityFramework.SqlServer.dll" #>
<## assembly name="$(DevEnvDir)..\IDE\EntityFramework.SqlServerCompact.dll" #>
<## import namespace="System.Linq" #>
<## import namespace="System.Text" #>
<## import namespace="System.Collections.Generic" #>
<## import namespace="System.Data.Entity" #>
<## import namespace="System.Data.Entity.Core.Metadata.Edm" #>
<## import namespace="Microsoft.Data.Entity.Design.DatabaseGeneration" #>
<## import namespace="System.Runtime.Remoting.Messaging" #>
<## import namespace="System.Text.RegularExpressions" #>
<## template language="C#" debug="true" hostspecific="true" #>
<## include file="GenerateTSQL.Utility.ttinclude"#>
<## output extension = ".sql" #>
<#
// +++++++++++++++++++++++++++++++++++++++++++++++++
// Setup for the template (initializing variables, etc.)
// +++++++++++++++++++++++++++++++++++++++++++++++++
string databaseName = this.GetInput<string>(EdmParameterBag.ParameterName.DatabaseName.ToString());
string edmxPath = this.GetInput<string>(EdmParameterBag.ParameterName.EdmxPath.ToString());
Version targetVersion = this.GetInput<Version>(EdmParameterBag.ParameterName.TargetVersion.ToString());
DbConfiguration.SetConfiguration(new TemplateDbConfiguration());
if (false == InitializeAndValidateExistingStore())
{
#>
-- Warning: There were errors validating the existing SSDL. Drop statements
-- will not be generated.
<#
}
#>
-- --------------------------------------------------
<#
if (this.IsSQLCE) {
#>
-- Entity Designer DDL Script for SQL Server Compact Edition
<#
} else {
#>
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
<#
}
#>
-- --------------------------------------------------
-- Date Created: <#=DateTime.Now#>
<#
if (!String.IsNullOrEmpty(edmxPath))
{
#>
-- Generated from EDMX file: <#=Id(edmxPath)#>
<#
}
#>
-- --------------------------------------------------
<# if (!this.IsSQLCE)
{
#>
SET QUOTED_IDENTIFIER OFF;
GO
<# if (!String.IsNullOrEmpty(databaseName))
{
#>
USE [<#=Id(databaseName)#>];
GO
<#
}
foreach (string unescapedSchemaName in (from es in Store.GetAllEntitySets() select es.GetSchemaName()).Distinct())
{
#>
IF SCHEMA_ID(N'<#=Lit(unescapedSchemaName)#>') IS NULL EXECUTE(N'CREATE SCHEMA [<#=Id(unescapedSchemaName)#>]');
<#
}
#>
GO
<# } #>
-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
<# if (this.IsSQLCE)
{
#>
-- NOTE: if the constraint does not exist, an ignorable error will be reported.
<# } #>
-- --------------------------------------------------
<#
foreach (AssociationSet associationSet in ExistingStore.GetAllAssociationSets())
{
ReferentialConstraint constraint = associationSet.ElementType.ReferentialConstraints.Single();
string constraintName = Id(WriteFKConstraintName(constraint));
AssociationSetEnd dependentSetEnd = associationSet.AssociationSetEnds.Where(ase => ase.CorrespondingAssociationEndMember == constraint.ToRole).Single();
string schemaName = Id(dependentSetEnd.EntitySet.GetSchemaName());
string dependentTableName = Id(dependentSetEnd.EntitySet.GetTableName());
if (!this.IsSQLCE)
{
#>
IF OBJECT_ID(N'[<#=Lit(schemaName)#>].[<#=Lit(constraintName)#>]', 'F') IS NOT NULL
<# } #>
ALTER TABLE <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>] DROP CONSTRAINT [<#=constraintName#>];
GO
<#
}
#>
-- --------------------------------------------------
-- Dropping existing tables
<# if (this.IsSQLCE)
{
#>
-- NOTE: if the table does not exist, an ignorable error will be reported.
<# } #>
-- --------------------------------------------------
<#
foreach (EntitySet entitySet in ExistingStore.GetAllEntitySets())
{
string schemaName = Id(entitySet.GetSchemaName());
string tableName = Id(entitySet.GetTableName());
if (!this.IsSQLCE)
{
#>
IF OBJECT_ID(N'[<#=Lit(schemaName)#>].[<#=Lit(tableName)#>]', 'U') IS NOT NULL
<# } #>
DROP TABLE <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=tableName#>];
GO
<#
}
#>
-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------
<#
foreach (EntitySet entitySet in Store.GetAllEntitySets())
{
string schemaName = Id(entitySet.GetSchemaName());
string tableName = Id(entitySet.GetTableName());
#>
-- Creating table '<#=tableName#>'
CREATE TABLE <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=tableName#>] (
<#
for (int p = 0; p < entitySet.ElementType.Properties.Count; p++)
{
EdmProperty prop = entitySet.ElementType.Properties[p];
#>
[<#=Id(prop.Name)#>] <#=prop.ToStoreType()#> <#=WriteIdentity(prop, targetVersion)#> <#=WriteNullable(prop.Nullable)#><#=(p < entitySet.ElementType.Properties.Count - 1) ? "," : ""#>
<#
}
#>
);
GO
<#
}
#>
-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------
<#
foreach (EntitySet entitySet in Store.GetAllEntitySets())
{
string schemaName = Id(entitySet.GetSchemaName());
string tableName = Id(entitySet.GetTableName());
#>
-- Creating primary key on <#=WriteColumns(entitySet.ElementType.GetKeyProperties(), ',')#> in table '<#=tableName#>'
ALTER TABLE <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=tableName#>]
ADD CONSTRAINT [PK_<#=tableName#>]
PRIMARY KEY <# if (!IsSQLCE) {#>CLUSTERED <#}#>(<#=WriteColumns(entitySet.ElementType.GetKeyProperties(), ',')#> <# if (!IsSQLCE) {#>ASC<#}#>);
GO
<#
}
#>
-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------
<#
foreach (AssociationSet associationSet in Store.GetAllAssociationSets())
{
ReferentialConstraint constraint = associationSet.ElementType.ReferentialConstraints.Single();
AssociationSetEnd dependentSetEnd = associationSet.AssociationSetEnds.Where(ase => ase.CorrespondingAssociationEndMember == constraint.ToRole).Single();
AssociationSetEnd principalSetEnd = associationSet.AssociationSetEnds.Where(ase => ase.CorrespondingAssociationEndMember == constraint.FromRole).Single();
string schemaName = Id(dependentSetEnd.EntitySet.GetSchemaName());
string dependentTableName = Id(dependentSetEnd.EntitySet.GetTableName());
string principalTableName = Id(principalSetEnd.EntitySet.GetTableName());
#>
-- Creating foreign key on <#=WriteColumns(constraint.ToProperties, ',')#> in table '<#=dependentTableName#>'
ALTER TABLE <#if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>]
ADD CONSTRAINT [<#=WriteFKConstraintName(constraint)#>]
FOREIGN KEY (<#=WriteColumns(constraint.ToProperties, ',')#>)
REFERENCES <# if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=principalTableName#>]
(<#=WriteColumns(constraint.FromProperties, ',')#>)
ON DELETE <#=GetDeleteAction(constraint)#> ON UPDATE NO ACTION;
GO
<#
// if the foreign keys are part of the primary key on the dependent end, then we should not add a constraint.
if (!dependentSetEnd.EntitySet.ElementType.GetKeyProperties().Take(constraint.ToProperties.Count()).OrderBy(r => r.Name).SequenceEqual(constraint.ToProperties.OrderBy(r => r.Name)))
{
#>
-- Creating non-clustered index for FOREIGN KEY '<#=WriteFKConstraintName(constraint)#>'
CREATE INDEX [IX_<#=WriteFKConstraintName(constraint)#>]
ON <#if (!IsSQLCE) {#>[<#=schemaName#>].<#}#>[<#=dependentTableName#>]
(<#=WriteColumns(constraint.ToProperties, ',')#>);
GO
<#
}
}
#>
-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------
This feature does not work for SQLite, as hinted at in the tt file:
<#
if (this.IsSQLCE) {
#>
-- Entity Designer DDL Script for SQL Server Compact Edition
<#
} else {
#>
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
<#
}
#>

web.config changes for KB3159706

i spent a few hours trying to code this by myself, but i don't know much about editing the web.config and all the examples i found don't come close to what i need. CHANGE#1 is unique because it does include the typical key=value.
I want to be able to script (PowerShell) the required modifications of Web.Config, only if the values do not already exist.
CHANGE#1:
Onsert this
(if not already there and "true"): multipleSiteBindingsEnabled="true"
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
CHANGE#2:
Insert this if not already there:
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="SSL"
contract="Microsoft.UpdateServices.Internal.IClientWebService" />
<endpoint address="secured"
binding="basicHttpBinding"
bindingConfiguration="SSL"
contract="Microsoft.UpdateServices.Internal.IClientWebService" />
It goes between here:
<services>
<service
name="Microsoft.UpdateServices.Internal.Client"
behaviorConfiguration="ClientWebServiceBehaviour">
<!-- ... CODE FROM CHANGE#2 GOES HERE ... -->
</service>
</services>
This is the code so far for change#1 (not working):
$sWSUSwebConfig = "C:\Program Files\Update Services\WebServices\ClientWebService\Web.Config"
$xFileContent = [Xml](Get-Content $sWSUSwebConfig)
$root = $xFileContent.get_DocumentElement()
foreach ($item in $root."system.serviceModel"."serviceHostingEnvironment") {
if ($item."multipleSiteBindingsEnabled" -ine "true") {
$activeConnection = $root.serviceHostingEnvironment
$activeConnection.SetAttribute("multipleSiteBindingsEnabled", "true")
#$item.add."multipleSiteBindingsEnabled" = "true"
$iKeyFound = $true
}
}
$xFileContent.Save("c:\temp\web.config")
Reference for modifications: step 3 from kb3159706.

Import all build files in a directory - phing

I need to include all xml files inside a directory (I dont know the name, and count of files) in my current build.xml using ImportTask.
This is my build.xml file:
<?xml version="1.0" encoding="utf-8"?>
<project name="New Project" basedir="." default="myimport">
<target name="myimport" description="dummy to import other build files">
<if>
<isset property="file" />
<then>
<echo msg="Importing ${file}" />
<import file="${file}" />
</then>
</if>
</target>
<if>
<not>
<isset property="dummy.property" />
</not>
<then>
<echo msg="Now include all files in ./dev/build directory" />
<property name="dummy.property" value="true" />
<foreach param="msg" absparam="file" target="myimport">
<fileset dir="./dev/build/">
<include name="*.xml"/>
</fileset>
</foreach>
</then>
</if>
</project>
and an example file in target directory:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" basedir="." default="dummy">
<target name="dummy" description="Dummy task">
<echo msg="Dummy task, just for test" />
</target>
<echo msg="Imported!" />
</project>
when I run phing -l the result is:
Buildfile: /home/f0rud/workspace/s/build.xml
[echo] Now include all files in ./dev/build directory
[foreach] Calling Buildfile '/home/f0rud/workspace/s/build.xml' with target 'myimport'
New Project > myimport:
[echo] Importing ./dev/build/test.xml
[echo] Imported!
Default target:
----------------------------------------------------------------------------
myimport dummy to import other build files
Main targets:
----------------------------------------------------------------------------
myimport dummy to import other build files
But there is no dummy (or test.dummy) target, why?
Note : There is a funny bug, if I remove the if part, I get Maximum function nesting level of '100' reached, aborting! error but thats not my problem (the if solve that problem.)
The problem is import work on global context.
When I call it inside a target, its not available in global context.
So I've written a simple Phing task to load all files of a fileset like so:
class ImportDirTask extends Task {
/** Array of filesets */
private $filesets = array();
/**
* Nested creator, adds a set of files (nested fileset attribute).
*/
function createFileSet() {
$num = array_push($this->filesets, new FileSet());
return $this->filesets[$num-1];
}
/**
* Parse a Phing build file and copy the properties, tasks, data types and
* targets it defines into the current project.
*
* #return void
*/
public function main () {
// filesets
foreach ($this->filesets as $fs) {
$ds = $fs->getDirectoryScanner($this->project);
$srcFiles = $ds->getIncludedFiles();
$srcDirs = $ds->getIncludedDirectories();
foreach ($srcFiles as $f)
{
$task = new ImportTask();
$task->setProject($this->project);
$task->init();
$task->setFile($this->file = $fs->getDir($this->project) . FileSystem::getFileSystem()->getSeparator() . $f);
$task->main();
}
}
} //end main
} //end ImportDirTask
It just work.