Click here to Skip to main content
15,892,199 members
Articles / Programming Languages / C#

Parsing the Entity Framework EDMX file

Rate me:
Please Sign up or sign in to vote.
4.38/5 (7 votes)
3 Jun 2010CPOL4 min read 58.5K   1.2K   26  
Looking at ways to parse an Entity Framework EDMX file
<#+
// <copyright file="Container.tt" company="Webbert Solutions, LLC">
//  Copyright © Webbert Solutions, LLC. All Rights Reserved.
// </copyright>

/// <summary>
/// 
/// </summary>
public class ContainerModel : Template
{
	public Container container;
	
    /// <summary>
    /// 
    /// </summary>
    public override string TransformText()
    {
#>
using System;
using System.Data.EntityClient;
using EFPocoAdapter;

namespace <#= container.Entities[0].Entity.EntityTypeNamespace #>
{
    public interface I<#= container.Name #>
    {
<#+ foreach (EntitySet entitySet in container.Entities) { #>
        IEntitySet<<#= entitySet.Entity.EntityTypeNamespace #>.<#= entitySet.Entity.EntityTypeName #>> <#= entitySet.Name #> { get; }
<#+ } #>
    }

    public partial class <#= container.Name #> : EFPocoContext<<#= container.Entities[0].Entity.EntityTypeNamespace #>.PocoAdapters.<#= container.Name #>Adapter>, I<#= container.Name #>
    {
        public <#= container.Name #>() : base(new <#= container.Entities[0].Entity.EntityTypeNamespace #>.PocoAdapters.<#= container.Name #>Adapter()) { }
        public <#= container.Name #>(string connectionString) : base(new <#= container.Entities[0].Entity.EntityTypeNamespace #>.PocoAdapters.<#= container.Name #>Adapter(connectionString)) { }
        public <#= container.Name #>(EntityConnection connection) : base(new <#= container.Entities[0].Entity.EntityTypeNamespace #>.PocoAdapters.<#= container.Name #>Adapter(connection)) { }
<#+ foreach (EntitySet entitySet in container.Entities) { #>

        public IEntitySet<<#= entitySet.Entity.EntityTypeNamespace #>.<#= entitySet.Entity.EntityTypeName #>> <#= entitySet.Name #>
        {
            get { return GetEntitySet<<#= entitySet.Entity.EntityTypeNamespace #>.<#= entitySet.Entity.EntityTypeName #>>("<#= entitySet.Name #>"); }
        }
<#+ } #>
    }
}
<#+
		return this.GenerationEnvironment.ToString();
	}
}
#>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Webbert Solutions
United States United States
Dave is an independent consultant working in a variety of industries utilizing Microsoft .NET technologies.

Comments and Discussions