26 September 2007
Entity Framework: генерування додаткових артефактів по моделі (DSL Tools)
Я вже колись припускав, що Entity Framework Tools розроблені на базі DSL Tools. Учора вирішив це перевірити. Все підтвердилось. Багато додаткового коду, але все одно це все побудовано за допомогою DSL Tools.
Одразу ж виникла ідея отримати додатковий коди за допомогою темплейтів. Теоретично якщо маємо модель, то достатньо додати *.tt файл, там в t4 форматі написати темплейт і все.
Отже додав файл Test.tt
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" #>
<#@ output extension=".txt" #>
<#@ EntityFramework processor="EntityFrameworkDirectiveProcessor" requires="fileName='AdventureWorks.edmx'" #>
Report template
<#= this.EntityDesignerViewModel.Alias #>
<#= this.EntityDesignerViewModel.Documentation #>
<#
// When you change the DSL Definition, some of the code below may not work.
foreach (object type in this.EntityDesignerViewModel.EntityTypes)
{
#>
<#= type.GetType().Name #>
<#
}
#>
Тут EntityFramework це процесор, назву я витяг з рефлетора.
EntityDesignerViewModel - кореневий елемент моделі. Інфа також з рефлетора.
Все добре, все зкоміплювалось. Але...
Error 12 Errors were generated when initializing the transformation object. The transformation will not be run. The following Exception was thrown:
System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(Int32 hr, Int32[] expectedHRFailure)
at Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(Int32 hr)
at Microsoft.Data.Entity.Design.VisualStudio.VsUtils.GetDocData(IServiceProvider site, String documentPath)
at Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignSerializationHelper.LoadModel(SerializationResult serializationResult, Partition partition, String fileName, ISchemaResolver schemaResolver, ValidationController validationController)
at Microsoft.Data.Entity.Design.EntityDesigner.MicrosoftDataEntityDesignSerializationHelperBase.LoadModel(SerializationResult serializationResult, Store store, String fileName, ISchemaResolver schemaResolver, ValidationController validationController)
at Microsoft.VisualStudio.TextTemplating1999061462098F63073F04A60E9D8C32.GeneratedTextTransformation.Initialize()
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(String fullClassName, String baseClassName, String[] importedNamespaces, String[] references, String source, String inputFile, Boolean debug, SupportedLanguages language, IDictionary`2 languageOptions, IFormatProvider format, ITextTemplatingEngineHost host, Boolean cacheAssemblies, String& result)
Нажаль, поки що я вирішити цю проблему не зміг ;(. Може пофіксять в наступній версії.
Буду ще копати, адже це супер якщо модель буде доступна. Можливостей море!
Вчу українську, багато працюю. Цікавлюсь моделюванням небезпек. Більшість часу витрачаю на .Net.