|
I've got another work-around to run by IB. In the T4 template for each model, I'm overriding the entity manager ctors and default manager creation which means I have a separate class (linked to the Silverlight project of course) that does the ctors and creation once.
It's a hack but until IB releases a fix, but this will get around the duplicate declarations.
Change the <modelname>.edmx.tt file that is auto-created for each *.edmx to (either plugging in your data model name where it says $edmxname$:
<#@ template language="C#" debug="true" hostSpecific="true" #> <#@ output extension=".ReadMe" #> <#@ Assembly Name="System.Core.dll" #> <#@ Assembly Name="System.Data.Entity.dll" #> <#@ Assembly Name="Microsoft.VisualStudio.TextTemplating.10.0" #> <#@ Assembly Name="IdeaBlade.Core" #> <#@ Assembly Name="IdeaBlade.VisualStudio.DTE.dll" #> <#@ Assembly Name="IdeaBlade.VisualStudio.OM.CodeGenerator.dll" #> <#@ Assembly Name="IdeaBlade.EntityModel.Edm.Metadata.dll" #> <#@ import namespace="System" #> <#@ import namespace="System.Reflection" #> <#@ import namespace="System.Data.Entity" #> <#@ import namespace="IdeaBlade.VisualStudio.DTE" #> <#@ import namespace="IdeaBlade.VisualStudio.OM.CodeGenerator" #> <#@ import namespace="IdeaBlade.EntityModel.Edm.Metadata" #> <# // Source for this file located at: $templateFullFileName$ // $edmxname$ <--- This is needed so that "Transform Related Text Templates On Save" works correctly. var template = new MyTemplate(this); template.Generate(); #> <#+ public class MyTemplate : DomainModelTemplate { public MyTemplate(Microsoft.VisualStudio.TextTemplating.TextTransformation textTransformation) :base(textTransformation) {} // HACK: override to prevent DevForce from generating the EM in the designer files // since it seems to get confused by multiple EDMX files using the same EM. // This means we have to have a partial class for the default em declared that does // the constructor/new-up of the EM and link that class in the Silverlight project protected override void WriteEntityManagerCtors(CsdlWrapper csdl) { WriteToOutputWindow("Suppressing Entity Manager Constructor Generation for: " + csdl.EntityManagerName); } protected override void WriteEntityManagerDefaultManager(CsdlWrapper csdl) { WriteToOutputWindow("Suppressing Entity Manager Default Manager Generation: " + csdl.EntityManagerName); } } #>
Adding a partial class for the Domain Model Entity Manager (the common EM shared across data models) and linking this class to the Silverlight project. For example:
MyEntityManager.cs (just copied the stuff from the *.IB.Designer.cs file):
using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.Serialization; using IbEm = IdeaBlade.EntityModel; using IbCore = IdeaBlade.Core; using IbVal = IdeaBlade.Validation;
namespace <yournamespacehere> {
/// <summary> /// The domain-specific EntityManager for your domain model. /// </summary> public partial class MyEntityManager : IbEm.EntityManager {
#region Constructors
/// <summary>See <see cref="M:IbEm.EntityManager.#ctor()"/>. </summary> public MyEntityManager() : base() { }
/// <summary>See <see cref="M:IbEm.EntityManager.#ctor(Boolean)"/>. </summary> public MyEntityManager(Boolean shouldConnect) : base(shouldConnect) { }
/// <summary>See <see cref="M:IbEm.EntityManager.#ctor(Boolean, String)"/>. </summary> public MyEntityManager(Boolean shouldConnect, String dataSourceExtension) : base(shouldConnect, dataSourceExtension) { }
/// <summary>See <see cref="M:IbEm.EntityManager.#ctor(Boolean, String, IbEm.EntityServiceOption)"/>. </summary> public MyEntityManager(Boolean shouldConnect, String dataSourceExtension, IbEm.EntityServiceOption entityServiceOption) : base(shouldConnect, dataSourceExtension, entityServiceOption) { }
/// <summary>See <see cref="M:IbEm.EntityManager.#ctor(IbEm.EntityManager)"/>. </summary> public MyEntityManager(IbEm.EntityManager entityManager) : base(entityManager) { }
/// <summary>See <see cref="M:IbEm.EntityManager.#ctor(IbEm.EntityManager, Boolean, String, IbEm.EntityServiceOption)"/>. </summary> public MyEntityManager(IbEm.EntityManager entityManager, Boolean shouldConnect, String dataSourceExtension, IbEm.EntityServiceOption entityServiceOption) : base(entityManager, shouldConnect, dataSourceExtension, entityServiceOption) { }
static MyEntityManager() { IbEm.EntityRelation.InitializeEntityRelations(Assembly.GetExecutingAssembly()); } #endregion Constructors
#region DefaultManager
/// <summary>Gets the default manager. </summary> public new static MyEntityManager DefaultManager { get { return GetDefaultEntityManager<MyEntityManager>(); } } #endregion DefaultManager
}
|