Skip to content

Commit

Permalink
Fix various issues for the first release
Browse files Browse the repository at this point in the history
  • Loading branch information
CZEMacLeod committed Sep 23, 2021
1 parent d0c90ed commit 545651c
Show file tree
Hide file tree
Showing 19 changed files with 341 additions and 41 deletions.
15 changes: 15 additions & 0 deletions C3D.MSBuild.Tools.EF6.GenerateViews.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{A547D473
Directory.Build.Props = Directory.Build.Props
Directory.Build.Targets = Directory.Build.Targets
build\InstallCert.ps1 = build\InstallCert.ps1
nuget.config = nuget.config
build\RemoveCert.ps1 = build\RemoveCert.ps1
build\Test.snk = build\Test.snk
EndProjectSection
Expand All @@ -29,6 +30,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{64F17F2D-6
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "C3D.MSBuild.Tools.EF6.GenerateViews", "src\C3D.MSBuild.Tools.EF6.GenerateViews\C3D.MSBuild.Tools.EF6.GenerateViews.csproj", "{76B9485A-002F-4036-A3C7-74D723A7A610}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{80B47DDE-BD61-4BDA-92E2-E8531B2386AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NETCoreConsoleApp", "samples\NETCoreConsoleApp\NETCoreConsoleApp.csproj", "{443911E9-9AAA-4449-9733-60BB973021A1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NETFrameworkConsoleApp", "samples\NETFrameworkConsoleApp\NETFrameworkConsoleApp.csproj", "{6CFBFB63-A369-4E6B-AA8B-F2B07A0373FB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,12 +46,20 @@ Global
{76B9485A-002F-4036-A3C7-74D723A7A610}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76B9485A-002F-4036-A3C7-74D723A7A610}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76B9485A-002F-4036-A3C7-74D723A7A610}.Release|Any CPU.Build.0 = Release|Any CPU
{443911E9-9AAA-4449-9733-60BB973021A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{443911E9-9AAA-4449-9733-60BB973021A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{443911E9-9AAA-4449-9733-60BB973021A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CFBFB63-A369-4E6B-AA8B-F2B07A0373FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CFBFB63-A369-4E6B-AA8B-F2B07A0373FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CFBFB63-A369-4E6B-AA8B-F2B07A0373FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{76B9485A-002F-4036-A3C7-74D723A7A610} = {E9CAD609-B2BF-42DD-83D4-4175F65CB9A6}
{443911E9-9AAA-4449-9733-60BB973021A1} = {80B47DDE-BD61-4BDA-92E2-E8531B2386AA}
{6CFBFB63-A369-4E6B-AA8B-F2B07A0373FB} = {80B47DDE-BD61-4BDA-92E2-E8531B2386AA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3858E63C-C6E7-4355-AB43-F79C83A17238}
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.Targets
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<Message Text="Package Tags: $(PackageTags)" Importance="high" />
</Target>

<Target Name="SetPackageDescription" DependsOnTargets="SetAssemblyVersions">
<Target Name="SetPackageDescription" DependsOnTargets="GetBuildVersion">
<PropertyGroup>
<PackageDescription>
Assembly Version: $(AssemblyVersion)
Expand Down
41 changes: 40 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# TODO
# C3D.MSBuild.Tools.EF6.GenerateViews

An MSBuild based implementation of the [`Entity Framework 6 Power Tools Community Edition`](https://github.com/ErikEJ/EntityFramework6PowerTools) `Generate Views` command.

The samples folder shows the use of the package with NETFramework and NETCore (.Net 5)

This is for EntityFramework 6 only - not EFCore

An example of how to get the EDMX file from your context file is given in the program main.
It will write the EDMX for the context to the executable folder.
You can copy this into your application directory.
Ensure it is _not_ set to any build action or have any custom tool attached.

Set the Build Action to EntityView

Set the Custom Tool Namespace to match your database context's namespace.

On build, the Views will be generated in the obj folder and automatically included in the build.

If you are using Code-First migrations, you can add the following to automatically generate views based on the last edmx file in the migrations folder.

```xml
<ItemGroup>
<EntityView Include="Migrations\**\*.edmx">
<CustomToolNamespace>GSHydro.CertificateManager.Models.DAL</CustomToolNamespace>
</EntityView>
</ItemGroup>
```

## Known Properties

`EntityFramework6GenerateViewsOutputDir` - Defaults to $(IntermediateOutputPath)\EntityViews

## Known Items

* `EntityView` - One or more edmx files used to generate the Views. Only the latest (alphabetically last) file is used.
** `CustomToolNamespace` - Property of the `EntityView` item used to determine the namespace of the DBContext. The DBContext name itself is determined from the EDMX file.



19 changes: 19 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSourceCredentials>
</packageSourceCredentials>
<packageSources>
<clear />
<add key="Local" value="$/../packages" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<activePackageSource>
<!-- All non-disabled sources are active -->
<add key="All" value="(Aggregate source)"/>
</activePackageSource>
<disabledPackageSources>
</disabledPackageSources>
</configuration>
42 changes: 42 additions & 0 deletions samples/NETCoreConsoleApp/Models/MyDBContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NETCoreConsoleApp.Models
{
public class SchoolContext : DbContext
{
public SchoolContext() : base()
{

}


public DbSet<Student> Students { get; set; }
public DbSet<Grade> Grades { get; set; }
}

public class Grade
{
public int GradeId { get; set; }
public string GradeName { get; set; }
public string Section { get; set; }

public ICollection<Student> Students { get; set; }
}

public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public DateTime? DateOfBirth { get; set; }
public byte[] Photo { get; set; }
public decimal Height { get; set; }
public float Weight { get; set; }

public Grade Grade { get; set; }
}
}
1 change: 1 addition & 0 deletions samples/NETCoreConsoleApp/Models/NETCoreConsoleApp.edmx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><Edmx Version="3.0" xmlns="http://schemas.microsoft.com/ado/2009/11/edmx"><Runtime><ConceptualModels><Schema Namespace="NETCoreConsoleApp.Models" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm"><EntityType Name="Grade" customannotation:ClrType="NETCoreConsoleApp.Models.Grade, NETCoreConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"><Key><PropertyRef Name="GradeId" /></Key><Property Name="GradeId" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" /><Property Name="GradeName" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" /><Property Name="Section" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" /><NavigationProperty Name="Students" Relationship="Self.Student_Grade" FromRole="Student_Grade_Target" ToRole="Student_Grade_Source" /></EntityType><EntityType Name="Student" customannotation:ClrType="NETCoreConsoleApp.Models.Student, NETCoreConsoleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"><Key><PropertyRef Name="StudentID" /></Key><Property Name="StudentID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" /><Property Name="StudentName" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" /><Property Name="DateOfBirth" Type="DateTime" /><Property Name="Photo" Type="Binary" MaxLength="Max" FixedLength="false" /><Property Name="Height" Type="Decimal" Precision="18" Scale="2" Nullable="false" /><Property Name="Weight" Type="Single" Nullable="false" /><NavigationProperty Name="Grade" Relationship="Self.Student_Grade" FromRole="Student_Grade_Source" ToRole="Student_Grade_Target" /></EntityType><Association Name="Student_Grade"><End Role="Student_Grade_Source" Type="Self.Student" Multiplicity="*" /><End Role="Student_Grade_Target" Type="Self.Grade" Multiplicity="0..1" /></Association><EntityContainer Name="SchoolContext" customannotation:UseClrTypes="true"><EntitySet Name="Grades" EntityType="Self.Grade" /><EntitySet Name="Students" EntityType="Self.Student" /><AssociationSet Name="Student_Grade" Association="Self.Student_Grade"><End Role="Student_Grade_Source" EntitySet="Students" /><End Role="Student_Grade_Target" EntitySet="Grades" /></AssociationSet></EntityContainer></Schema></ConceptualModels><Mappings><Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs"><EntityContainerMapping StorageEntityContainer="CodeFirstDatabase" CdmEntityContainer="SchoolContext"><EntitySetMapping Name="Grades"><EntityTypeMapping TypeName="NETCoreConsoleApp.Models.Grade"><MappingFragment StoreEntitySet="Grade"><ScalarProperty Name="GradeId" ColumnName="GradeId" /><ScalarProperty Name="GradeName" ColumnName="GradeName" /><ScalarProperty Name="Section" ColumnName="Section" /></MappingFragment></EntityTypeMapping></EntitySetMapping><EntitySetMapping Name="Students"><EntityTypeMapping TypeName="NETCoreConsoleApp.Models.Student"><MappingFragment StoreEntitySet="Student"><ScalarProperty Name="StudentID" ColumnName="StudentID" /><ScalarProperty Name="StudentName" ColumnName="StudentName" /><ScalarProperty Name="DateOfBirth" ColumnName="DateOfBirth" /><ScalarProperty Name="Photo" ColumnName="Photo" /><ScalarProperty Name="Height" ColumnName="Height" /><ScalarProperty Name="Weight" ColumnName="Weight" /></MappingFragment></EntityTypeMapping></EntitySetMapping><AssociationSetMapping Name="Student_Grade" TypeName="NETCoreConsoleApp.Models.Student_Grade" StoreEntitySet="Student"><EndProperty Name="Student_Grade_Target"><ScalarProperty Name="GradeId" ColumnName="Grade_GradeId" /></EndProperty><EndProperty Name="Student_Grade_Source"><ScalarProperty Name="StudentID" ColumnName="StudentID" /></EndProperty><Condition IsNull="false" ColumnName="Grade_GradeId" /></AssociationSetMapping></EntityContainerMapping></Mapping></Mappings><StorageModels><Schema Namespace="CodeFirstDatabaseSchema" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl"><EntityType Name="Grade"><Key><PropertyRef Name="GradeId" /></Key><Property Name="GradeId" Type="int" StoreGeneratedPattern="Identity" Nullable="false" /><Property Name="GradeName" Type="nvarchar(max)" Nullable="true" /><Property Name="Section" Type="nvarchar(max)" Nullable="true" /></EntityType><EntityType Name="Student"><Key><PropertyRef Name="StudentID" /></Key><Property Name="StudentID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" /><Property Name="StudentName" Type="nvarchar(max)" Nullable="true" /><Property Name="DateOfBirth" Type="datetime" Nullable="true" /><Property Name="Photo" Type="varbinary(max)" Nullable="true" /><Property Name="Height" Type="decimal" Precision="18" Scale="2" Nullable="false" /><Property Name="Weight" Type="real" Nullable="false" /><Property Name="Grade_GradeId" Type="int" customannotation:Index="{ Name: IX_Grade_GradeId, Order: 0 }" Nullable="true" /></EntityType><Association Name="Student_Grade"><End Role="Grade" Type="Self.Grade" Multiplicity="0..1" /><End Role="Student" Type="Self.Student" Multiplicity="*" /><ReferentialConstraint><Principal Role="Grade"><PropertyRef Name="GradeId" /></Principal><Dependent Role="Student"><PropertyRef Name="Grade_GradeId" /></Dependent></ReferentialConstraint></Association><EntityContainer Name="CodeFirstDatabase"><EntitySet Name="Grade" EntityType="Self.Grade" Schema="dbo" Table="Grades" /><EntitySet Name="Student" EntityType="Self.Student" Schema="dbo" Table="Students" /><AssociationSet Name="Student_Grade" Association="Self.Student_Grade"><End Role="Grade" EntitySet="Grade" /><End Role="Student" EntitySet="Student" /></AssociationSet></EntityContainer></Schema></StorageModels></Runtime><Designer><Connection><DesignerInfoPropertySet><DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" /></DesignerInfoPropertySet></Connection><Options><DesignerInfoPropertySet><DesignerProperty Name="ValidateOnBuild" Value="False" /><DesignerProperty Name="CodeGenerationStrategy" Value="None" /><DesignerProperty Name="ProcessDependentTemplatesOnSave" Value="False" /><DesignerProperty Name="UseLegacyProvider" Value="False" /></DesignerInfoPropertySet></Options><Diagrams /></Designer></Edmx>
22 changes: 22 additions & 0 deletions samples/NETCoreConsoleApp/NETCoreConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<EntityView Include="Models\NETCoreConsoleApp.edmx">
<CustomToolNamespace>NETCoreConsoleApp.Models</CustomToolNamespace>
</EntityView>
</ItemGroup>

<ItemGroup>
<PackageReference Include="C3D.MSBuild.Tools.EF6.GenerateViews" Version="6.4.3-gd0c90ed8c3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="EntityFramework" Version="6.4.0" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions samples/NETCoreConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NETCoreConsoleApp.Models;
using System;

namespace NETCoreConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
using (var ctx = new SchoolContext())
{
var stud = new Student() { StudentName = "Bill" };

ctx.Students.Add(stud);
ctx.SaveChanges();

using (var edmxFile = System.IO.File.OpenWrite(
System.IO.Path.ChangeExtension(ctx.GetType().Assembly.Location, ".edmx")))
{
using (var edmx = System.Xml.XmlWriter.Create(edmxFile)) {
System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(ctx, edmx);
}
}
}
}
}
}
42 changes: 42 additions & 0 deletions samples/NETFrameworkConsoleApp/Models/MyDBContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NETFrameworkConsoleApp.Models
{
public class SchoolContext : DbContext
{
public SchoolContext() : base()
{

}


public DbSet<Student> Students { get; set; }
public DbSet<Grade> Grades { get; set; }
}

public class Grade
{
public int GradeId { get; set; }
public string GradeName { get; set; }
public string Section { get; set; }

public ICollection<Student> Students { get; set; }
}

public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public DateTime? DateOfBirth { get; set; }
public byte[] Photo { get; set; }
public decimal Height { get; set; }
public float Weight { get; set; }

public Grade Grade { get; set; }
}
}
Loading

0 comments on commit 545651c

Please sign in to comment.