Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Cinorid/Dbml2Ef
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.3
Choose a base ref
...
head repository: Cinorid/Dbml2Ef
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on May 7, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2abf06e View commit details

Commits on May 8, 2023

  1. Copy the full SHA
    7ceacd2 View commit details

Commits on Jun 2, 2023

  1. Copy the full SHA
    4083db5 View commit details
Showing with 15 additions and 6 deletions.
  1. +1 −0 Dbml2Ef/DBML/Association.cs
  2. +3 −3 Dbml2Ef/Dbml2Ef.csproj
  3. +11 −3 Dbml2Ef/Program.cs
1 change: 1 addition & 0 deletions Dbml2Ef/DBML/Association.cs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ public class Association
public string? Member { get; set; }
public string? ThisKey { get; set; }
public string? OtherKey { get; set; }
public string? Cardinality { get; set; }

public override string ToString()
{
6 changes: 3 additions & 3 deletions Dbml2Ef/Dbml2Ef.csproj
Original file line number Diff line number Diff line change
@@ -2,19 +2,19 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<PackAsTool>true</PackAsTool>
<AssemblyVersion>0.1.3</AssemblyVersion>
<AssemblyVersion>0.1.5</AssemblyVersion>
<AssemblyName>dbml2ef</AssemblyName>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<Title>Cinorid.dbml2ef</Title>
<PackageId>Cinorid.dbml2ef</PackageId>
<Version>0.1.3</Version>
<Version>0.1.5</Version>
<Authors>Cinorid (AhmadReza Saghari)</Authors>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Summary>linq2sql or Visual Studio DBML file to Entity Framework models converter</Summary>
14 changes: 11 additions & 3 deletions Dbml2Ef/Program.cs
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ private static void GenerateModelClass(Database dbModelDatabase, string namespac
{
foreach (var table in dbModelDatabase.Tables)
{
var fileName = table.Name + ".cs";
var fileName = table.Type + ".cs";
Console.WriteLine($"Generating {fileName}");

var strBuilder = new StringBuilder();
@@ -133,11 +133,18 @@ private static void GenerateModelClass(Database dbModelDatabase, string namespac
{
if (association.IsForeignKey)
{
strBuilder.AppendLine($"{namespaceIndentation} public virtual {association.Type} {association.Member} {{ get; set; }} = null!;");
strBuilder.AppendLine($"{namespaceIndentation} public virtual {association.Type} {(association.ThisKey == association.OtherKey ? "IdNavigation" : association.Member)} {{ get; set; }} = null!;");
}
else
{
strBuilder.AppendLine($"{namespaceIndentation} public virtual ICollection<{association.Type}> {association.Member} {{ get; set; }} = new List<{association.Type}>();");
if (association.Cardinality == "One")
{
strBuilder.AppendLine($"{namespaceIndentation} public virtual {association.Type}? {association.Type} {{ get; set; }}");
}
else
{
strBuilder.AppendLine($"{namespaceIndentation} public virtual ICollection<{association.Type}> {association.Member} {{ get; set; }} = new List<{association.Type}>();");
}
}

strBuilder.AppendLine("");
@@ -289,6 +296,7 @@ private static DBML.Database ConvertXElementToDatabase(XElement content)
association.ThisKey = elementColumn?.Attribute("ThisKey")?.Value;
association.OtherKey = elementColumn?.Attribute("OtherKey")?.Value;
association.Member = elementColumn?.Attribute("Member")?.Value;
association.Cardinality = elementColumn?.Attribute("Cardinality")?.Value;

var isForeignKey = elementColumn?.Attribute("IsForeignKey")?.Value;
association.IsForeignKey = Convert.ToBoolean(isForeignKey ?? false.ToString());