Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Npgsql.EntityFramework/NpgsqlSchema.msl
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@
</cs:EndProperty>
</cs:AssociationSetMapping>
<cs:AssociationSetMapping Name="ViewConstraintColumns" StoreEntitySet="PgViewConstraintColumns" TypeName="Store.TableOrViewConstraintColumn">
<cs:EndProperty Name="Column">
<cs:EndProperty Name="Constraint">
<cs:ScalarProperty Name="Id" ColumnName="constraint_id"/>
</cs:EndProperty>
<cs:EndProperty Name="Constraint">
<cs:EndProperty Name="Column">
<cs:ScalarProperty Name="Id" ColumnName="column_id"/>
</cs:EndProperty>
</cs:AssociationSetMapping>
Expand Down
143 changes: 135 additions & 8 deletions Npgsql.EntityFramework/NpgsqlSchema.ssdl
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,65 @@
</DefiningQuery>
</EntitySet>

<AssociationSet Association="NpgsqlSchema.TableTableColumn" Name="TableTableColumns" />
<AssociationSet Association="NpgsqlSchema.TableTableConstraint" Name="TableTableConstraints"/>
<AssociationSet Association="NpgsqlSchema.TableConstraintColumn" Name="TableConstraintColumns"/>
<AssociationSet Association="NpgsqlSchema.RelationshipRelationshipColumnMap" Name="RelationshipRelationshipColumnMaps" />
<AssociationSet Association="NpgsqlSchema.FromColumnRelationshipColumnMap" Name="FromColumnRelationshipColumnMaps" />
<AssociationSet Association="NpgsqlSchema.ToColumnRelationshipColumnMap" Name="ToColumnRelationshipColumnMaps" />
<AssociationSet Association="NpgsqlSchema.ViewViewColumn" Name="ViewViewColumns" />
<AssociationSet Association="NpgsqlSchema.FunctionFunctionParameter" Name="FunctionFunctionParameters" />
<AssociationSet Association="NpgsqlSchema.TableTableColumn" Name="TableTableColumns">
<End Role="Table" EntitySet="PgTables" />
<End Role="TableColumn" EntitySet="PgTableColumns" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.TableTableConstraint" Name="TableTableConstraints">
<End Role="Table" EntitySet="PgTables" />
<End Role="Constraint" EntitySet="PgConstraints" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.TableConstraintColumn" Name="TableConstraintColumns">
<End Role="Constraint" EntitySet="PgConstraints" />
<End Role="ConstraintColumn" EntitySet="PgConstraintColumns" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.RelationshipRelationshipColumnMap" Name="RelationshipRelationshipColumnMaps">
<End Role="ForeignKey" EntitySet="PgConstraints" />
<End Role="ForeignKeyColumn" EntitySet="PgForeignKeyColumns" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.FromColumnRelationshipColumnMap" Name="FromColumnRelationshipColumnMaps">
<End Role="TableColumn" EntitySet="PgTableColumns" />
<End Role="ForeignKeyColumn" EntitySet="PgForeignKeyColumns" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.ToColumnRelationshipColumnMap" Name="ToColumnRelationshipColumnMaps">
<End Role="TableColumn" EntitySet="PgTableColumns" />
<End Role="ForeignKeyColumn" EntitySet="PgForeignKeyColumns" />
</AssociationSet>

<AssociationSet Association="NpgsqlSchema.ViewViewColumn" Name="ViewViewColumns">
<End Role="View" EntitySet="PgViews" />
<End Role="ViewColumn" EntitySet="PgViewColumns" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.ViewViewConstraint" Name="ViewViewConstraints">
<End Role="View" EntitySet="PgViews" />
<End Role="Constraint" EntitySet="PgViewConstraints" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.ViewConstraintConstraintColumn" Name="ViewConstraintConstraintColumns">
<End Role="Constraint" EntitySet="PgViewConstraints" />
<End Role="ConstraintColumn" EntitySet="PgViewConstraintColumns" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.ViewConstraintForeignKey" Name="ViewConstraintForeignKeys">
<End Role="Constraint" EntitySet="PgViewConstraints" />
<End Role="ForeignKeyColumn" EntitySet="PgViewForeignKeyColumns" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.FromForeignKeyViewColumn" Name="FromForeignKeyViewColumns">
<End Role="ViewColumn" EntitySet="PgViewColumns" />
<End Role="ForeignKeyColumn" EntitySet="PgViewForeignKeyColumns" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.ToForeignKeyViewColumn" Name="ToForeignKeyViewColumns">
<End Role="ViewColumn" EntitySet="PgViewColumns" />
<End Role="ForeignKeyColumn" EntitySet="PgViewForeignKeyColumns" />
</AssociationSet>

<AssociationSet Association="NpgsqlSchema.FunctionFunctionParameter" Name="FunctionFunctionParameters">
<End Role="Function" EntitySet="PgFunctions" />
<End Role="FunctionParameter" EntitySet="PgFunctionParameters" />
</AssociationSet>
<AssociationSet Association="NpgsqlSchema.ProcedureProcedureParameter" Name="ProcedureProcedureParameters">
<End Role="Procedure" EntitySet="PgProcedures" />
<End Role="ProcedureParameter" EntitySet="PgProcedureParameters" />
</AssociationSet>

</EntityContainer>
<EntityType Name="Table">
<Key>
Expand Down Expand Up @@ -625,6 +676,7 @@
<Property Name="column_id" Type="varchar" Nullable="false"/>
<Property Name="constraint_id" Type="varchar" Nullable="false"/>
</EntityType>

<Association Name="TableTableColumn">
<End Type="NpgsqlSchema.Table" Role="Table" Multiplicity="1"/>
<End Type="NpgsqlSchema.TableColumn" Role="TableColumn" Multiplicity="*"/>
Expand Down Expand Up @@ -697,6 +749,7 @@
</Dependent>
</ReferentialConstraint>
</Association>

<Association Name="ViewViewColumn">
<End Type="NpgsqlSchema.View" Role="View" Multiplicity="1"/>
<End Type="NpgsqlSchema.ViewColumn" Role="ViewColumn" Multiplicity="*"/>
Expand All @@ -709,6 +762,67 @@
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="ViewViewConstraint">
<End Type="NpgsqlSchema.View" Role="View" Multiplicity="1" />
<End Type="NpgsqlSchema.ViewConstraint" Role="Constraint" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="View">
<PropertyRef Name="id" />
</Principal>
<Dependent Role="Constraint">
<PropertyRef Name="view_id" />
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="ViewConstraintConstraintColumn">
<End Type="NpgsqlSchema.ViewConstraint" Role="Constraint" Multiplicity="1" />
<End Type="NpgsqlSchema.ViewConstraintColumn" Role="ConstraintColumn" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Constraint">
<PropertyRef Name="id" />
</Principal>
<Dependent Role="ConstraintColumn">
<PropertyRef Name="constraint_id" />
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="ViewConstraintForeignKey">
<End Type="NpgsqlSchema.ViewConstraint" Role="Constraint" Multiplicity="1" />
<End Type="NpgsqlSchema.ViewForeignKeyColumn" Role="ForeignKeyColumn" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Constraint">
<PropertyRef Name="id" />
</Principal>
<Dependent Role="ForeignKeyColumn">
<PropertyRef Name="constraint_id" />
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="FromForeignKeyViewColumn">
<End Type="NpgsqlSchema.ViewColumn" Role="ViewColumn" Multiplicity="1" />
<End Type="NpgsqlSchema.ViewForeignKeyColumn" Role="ForeignKeyColumn" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="ViewColumn">
<PropertyRef Name="id" />
</Principal>
<Dependent Role="ForeignKeyColumn">
<PropertyRef Name="from_columnid" />
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="ToForeignKeyViewColumn">
<End Type="NpgsqlSchema.ViewColumn" Role="ViewColumn" Multiplicity="1" />
<End Type="NpgsqlSchema.ViewForeignKeyColumn" Role="ForeignKeyColumn" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="ViewColumn">
<PropertyRef Name="id" />
</Principal>
<Dependent Role="ForeignKeyColumn">
<PropertyRef Name="to_columnid" />
</Dependent>
</ReferentialConstraint>
</Association>

<Association Name="FunctionFunctionParameter">
<End Type="NpgsqlSchema.Function" Role="Function" Multiplicity="1"/>
<End Type="NpgsqlSchema.FunctionParameter" Role="FunctionParameter" Multiplicity="*"/>
Expand All @@ -721,4 +835,17 @@
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="ProcedureProcedureParameter">
<End Type="NpgsqlSchema.Procedure" Role="Procedure" Multiplicity="1" />
<End Type="NpgsqlSchema.ProcedureParameter" Role="ProcedureParameter" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Procedure">
<PropertyRef Name="id" />
</Principal>
<Dependent Role="ProcedureParameter">
<PropertyRef Name="procedure_id" />
</Dependent>
</ReferentialConstraint>
</Association>

</Schema>
75 changes: 75 additions & 0 deletions tests/EntityFrameworkBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Common;
using System.Xml;
using System.IO;

namespace NpgsqlTests
{
Expand Down Expand Up @@ -250,6 +255,76 @@ public void TestComputedValue()
}


[Test]
public void TestSchemaInformation()
{
// Obtain Npgsql.NpgsqlServices, Npgsql.EntityFramework via EntityFramework 6.0
DbProviderServices providerServices = DbProviderServices.GetProviderServices(Conn);
Assert.IsNotNull(providerServices);

// 9.3.1 or such
string providerManifestToken = providerServices.GetProviderManifestToken(Conn);
Assert.IsNotNullOrEmpty(providerManifestToken);

// Obtain NpgsqlProviderManifest
DbProviderManifest providerManifest = providerServices.GetProviderManifest(providerManifestToken) as DbProviderManifest;
Assert.IsNotNull(providerManifest);

// ssdl v1 from Npgsql.EntityFramework
XmlReader xmlSsdl = providerManifest.GetInformation("StoreSchemaDefinition") as XmlReader;
Assert.IsNotNull(xmlSsdl);

// msl v1 from Npgsql.EntityFramework
XmlReader xmlMsl = providerManifest.GetInformation("StoreSchemaMapping") as XmlReader;
Assert.IsNotNull(xmlMsl);

// csdl v1 from EntityFramework 6.0
XmlReader xmlCsdl = DbProviderServices.GetConceptualSchemaDefinition(DbProviderManifest.ConceptualSchemaDefinition);
Assert.IsNotNull(xmlCsdl);

// Create temp xml files. need cleaning!
string tmp = Guid.NewGuid().ToString("N");
string csdl = Path.Combine(Path.GetTempPath(), tmp + ".csdl");
string ssdl = Path.Combine(Path.GetTempPath(), tmp + ".ssdl");
string msl = Path.Combine(Path.GetTempPath(), tmp + ".msl");

XmlDocument xmldom = new XmlDocument();
xmldom.Load(xmlCsdl);
xmldom.Save(csdl);

xmldom.Load(xmlSsdl);
xmldom.Save(ssdl);

xmldom.Load(xmlMsl);
xmldom.Save(msl);

// http://msdn.microsoft.com/en-US/library/bb738533(v=vs.110).aspx

EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();

entityBuilder.Provider = "Npgsql";
entityBuilder.ProviderConnectionString = ConnectionStringEF;
entityBuilder.Metadata = csdl + "|" + ssdl + "|" + msl;

using (var context = new Store.SchemaInformation(new EntityConnection(entityBuilder.ToString())))
{
var tables = context.Tables;
Assert.Contains("Blogs", tables.Select(p => p.Name).ToArray());
Assert.Contains("Posts", tables.Select(p => p.Name).ToArray());

//var functions = context.Functions;
//Assert.Contains("pass_thru_int", functions.Select(p => p.Name).ToArray());
//Assert.Contains("pass_thru_str", functions.Select(p => p.Name).ToArray());

var tableConstraints = context.TableConstraints;
Assert.Contains("Blogs.BlogId", tableConstraints.OfType<Store.PrimaryKeyConstraint>().SelectMany(p => p.Columns).Select(p => p.Parent.Name + "." + p.Name).ToArray());
Assert.Contains("Posts.PostId", tableConstraints.OfType<Store.PrimaryKeyConstraint>().SelectMany(p => p.Columns).Select(p => p.Parent.Name + "." + p.Name).ToArray());

Assert.Contains("Posts.BlogId->Blogs.BlogId", tableConstraints.OfType<Store.ForeignKeyConstraint>().SelectMany(p => p.ForeignKeys).Select(p => p.FromColumn.Parent.Name + "." + p.FromColumn.Name + "->" + p.ToColumn.Parent.Name + "." + p.ToColumn.Name).ToArray());
}
}


//Hunting season is open Happy hunting on OrderBy,GroupBy,Min,Max,Skip,Take,ThenBy... and all posible combinations
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/NpgsqlTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<Compile Include="FunctionTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="SchemaInformation.cs" />
<Compile Include="TestMetrics.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="CommandTests.cs" />
Expand Down
Loading