Skip to content
Open
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
2 changes: 1 addition & 1 deletion Build/Build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<MajorVersion>1</MajorVersion>
<MinorVersion>3</MinorVersion>
<VersionStartYear>2012</VersionStartYear>
<BuildNumber>1</BuildNumber>
<BuildNumber>3</BuildNumber>
<Revision Condition="'$(Revision)' == ''">$(BuildNumber)</Revision>
<Version>$(MajorVersion).$(MinorVersion).$(BuildNumber).$(Revision)</Version>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions Common/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("1.3.1.0")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: AssemblyVersion("1.3.3.0")]
[assembly: AssemblyFileVersion("1.3.3.0")]
2 changes: 1 addition & 1 deletion Efmap.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Efmap</id>
<version>1.3.1.0</version>
<version>1.3.3.0</version>
<authors>Rui Carvalho</authors>
<owners>Rui Carvalho</owners>
<licenseUrl>http://opensource.org/licenses/MIT</licenseUrl>
Expand Down
42 changes: 41 additions & 1 deletion Src/Efmap/Helpers/DbContextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Metadata.Edm;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
Expand All @@ -9,6 +8,7 @@
using System.Data.Entity;
using System.Reflection;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Configuration;
using System.Data.Entity.Infrastructure;
using Efmap.Bootstrap;
using System.IO;
Expand Down Expand Up @@ -99,6 +99,46 @@ public static void AutoLoadForThisContext(this DbContext context, DbModelBuilder
}
}

public static void AutoLoadForThisContextWithDbSet(this DbContext context, DbModelBuilder modelBuilder)
{
//verify options for modelbuilder before
if (InitializerFactory.IsOptionActivated("RemoveMetaDataStatus"))
{
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
}

Type tc = context.GetType();
var props = tc.GetProperties().Where(
p => p.PropertyType.IsGenericType
&& p.PropertyType.GetGenericTypeDefinition() == typeof(DbSet<>)

).Select(s => s.PropertyType.GetGenericArguments());

Assembly asm = Assembly.GetAssembly(context.GetType());
Type loadType = typeof(EntityTypeConfiguration<>);

foreach (var dataType in props)
{
Type checkType = loadType.MakeGenericType(dataType);
var findType = asm.GetTypes().Where(t => t.BaseType == checkType).FirstOrDefault();
if (findType != null)
{
var obj = Activator.CreateInstance(findType);
Type registrar = typeof(ConfigurationRegistrar);
MethodInfo[] registrarMethods = registrar.GetMethods()
.Where(m => m.Name == "Add" && (m.GetGenericArguments().Where(p => p.Name == "TEntityType").Count() == 1)).ToArray();
if (registrarMethods.Length == 1)
{
MethodInfo registrarAdd = registrarMethods[0];
MethodInfo genericAdd = registrarAdd.MakeGenericMethod(dataType);

var result = genericAdd.Invoke(modelBuilder.Configurations, new[] { obj });
}

}

}
}

public static string GetSqlCreationScript(this DbContext context)
{
Expand Down