Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » Data Access » Downloads
 
Add your own
alternative version

Implementing Repository Pattern With Entity Framework

, 2 Nov 2012 CPOL
Implement Repository Pattern in data access layer with Entity Framework 4.0 and Below version( Working with ObjectContext and EntityObject )
RepositoryProjectPOC_Revised_-noexe.zip
RepositoryProjectSample
RepositoryProjectSample
DataModel.edmx
Helper
Implementations
Entity Framework
Interfaces
obj
x86
Debug
edmxResourcesToEmbed
DataModel.csdl
DataModel.msl
DataModel.ssdl
Properties
RepositoryProjectSample.suo
RepositoryProjectPOC_Revised_.zip
DataModel.edmx
DataModel.csdl
DataModel.msl
DataModel.ssdl
RepositoryProjectSample.exe
TempPE
DataModel.Designer.cs.dll
RepositoryProjectSample.suo
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;

[assembly: EdmSchemaAttribute()]
#region EDM Relationship Metadata

[assembly: EdmRelationshipAttribute("ProjectCodeModel", "FK_dbo_BlogPosts_dbo_Categories_CategoryId", "Categories", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(RepositoryProjectSample.Category), "BlogPosts", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(RepositoryProjectSample.BlogPost), true)]

#endregion

namespace RepositoryProjectSample
{
    #region Contexts
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public partial class ProjectCodeEntities : ObjectContext
    {
        #region Constructors
    
        /// <summary>
        /// Initializes a new ProjectCodeEntities object using the connection string found in the 'ProjectCodeEntities' section of the application configuration file.
        /// </summary>
        public ProjectCodeEntities() : base("name=ProjectCodeEntities", "ProjectCodeEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new ProjectCodeEntities object.
        /// </summary>
        public ProjectCodeEntities(string connectionString) : base(connectionString, "ProjectCodeEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new ProjectCodeEntities object.
        /// </summary>
        public ProjectCodeEntities(EntityConnection connection) : base(connection, "ProjectCodeEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        #endregion
    
        #region Partial Methods
    
        partial void OnContextCreated();
    
        #endregion
    
        #region ObjectSet Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<C__MigrationHistory> C__MigrationHistory
        {
            get
            {
                if ((_C__MigrationHistory == null))
                {
                    _C__MigrationHistory = base.CreateObjectSet<C__MigrationHistory>("C__MigrationHistory");
                }
                return _C__MigrationHistory;
            }
        }
        private ObjectSet<C__MigrationHistory> _C__MigrationHistory;
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<BlogPost> BlogPosts
        {
            get
            {
                if ((_BlogPosts == null))
                {
                    _BlogPosts = base.CreateObjectSet<BlogPost>("BlogPosts");
                }
                return _BlogPosts;
            }
        }
        private ObjectSet<BlogPost> _BlogPosts;
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Category> Categories
        {
            get
            {
                if ((_Categories == null))
                {
                    _Categories = base.CreateObjectSet<Category>("Categories");
                }
                return _Categories;
            }
        }
        private ObjectSet<Category> _Categories;

        #endregion

        #region AddTo Methods
    
        /// <summary>
        /// Deprecated Method for adding a new object to the C__MigrationHistory EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToC__MigrationHistory(C__MigrationHistory c__MigrationHistory)
        {
            base.AddObject("C__MigrationHistory", c__MigrationHistory);
        }
    
        /// <summary>
        /// Deprecated Method for adding a new object to the BlogPosts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToBlogPosts(BlogPost blogPost)
        {
            base.AddObject("BlogPosts", blogPost);
        }
    
        /// <summary>
        /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToCategories(Category category)
        {
            base.AddObject("Categories", category);
        }

        #endregion

    }

    #endregion

    #region Entities
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="ProjectCodeModel", Name="BlogPost")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class BlogPost : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new BlogPost object.
        /// </summary>
        /// <param name="id">Initial value of the Id property.</param>
        /// <param name="publishDate">Initial value of the PublishDate property.</param>
        /// <param name="categoryId">Initial value of the CategoryId property.</param>
        public static BlogPost CreateBlogPost(global::System.Guid id, global::System.DateTime publishDate, global::System.Guid categoryId)
        {
            BlogPost blogPost = new BlogPost();
            blogPost.Id = id;
            blogPost.PublishDate = publishDate;
            blogPost.CategoryId = categoryId;
            return blogPost;
        }

        #endregion

        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Guid Id
        {
            get
            {
                return _Id;
            }
            set
            {
                if (_Id != value)
                {
                    OnIdChanging(value);
                    ReportPropertyChanging("Id");
                    _Id = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("Id");
                    OnIdChanged();
                }
            }
        }
        private global::System.Guid _Id;
        partial void OnIdChanging(global::System.Guid value);
        partial void OnIdChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String Title
        {
            get
            {
                return _Title;
            }
            set
            {
                OnTitleChanging(value);
                ReportPropertyChanging("Title");
                _Title = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("Title");
                OnTitleChanged();
            }
        }
        private global::System.String _Title;
        partial void OnTitleChanging(global::System.String value);
        partial void OnTitleChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String Content
        {
            get
            {
                return _Content;
            }
            set
            {
                OnContentChanging(value);
                ReportPropertyChanging("Content");
                _Content = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("Content");
                OnContentChanged();
            }
        }
        private global::System.String _Content;
        partial void OnContentChanging(global::System.String value);
        partial void OnContentChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.DateTime PublishDate
        {
            get
            {
                return _PublishDate;
            }
            set
            {
                OnPublishDateChanging(value);
                ReportPropertyChanging("PublishDate");
                _PublishDate = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("PublishDate");
                OnPublishDateChanged();
            }
        }
        private global::System.DateTime _PublishDate;
        partial void OnPublishDateChanging(global::System.DateTime value);
        partial void OnPublishDateChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Guid CategoryId
        {
            get
            {
                return _CategoryId;
            }
            set
            {
                OnCategoryIdChanging(value);
                ReportPropertyChanging("CategoryId");
                _CategoryId = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("CategoryId");
                OnCategoryIdChanged();
            }
        }
        private global::System.Guid _CategoryId;
        partial void OnCategoryIdChanging(global::System.Guid value);
        partial void OnCategoryIdChanged();

        #endregion

    
        #region Navigation Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("ProjectCodeModel", "FK_dbo_BlogPosts_dbo_Categories_CategoryId", "Categories")]
        public Category Category
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("ProjectCodeModel.FK_dbo_BlogPosts_dbo_Categories_CategoryId", "Categories").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("ProjectCodeModel.FK_dbo_BlogPosts_dbo_Categories_CategoryId", "Categories").Value = value;
            }
        }
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<Category> CategoryReference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("ProjectCodeModel.FK_dbo_BlogPosts_dbo_Categories_CategoryId", "Categories");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Category>("ProjectCodeModel.FK_dbo_BlogPosts_dbo_Categories_CategoryId", "Categories", value);
                }
            }
        }

        #endregion

    }
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="ProjectCodeModel", Name="C__MigrationHistory")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class C__MigrationHistory : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new C__MigrationHistory object.
        /// </summary>
        /// <param name="migrationId">Initial value of the MigrationId property.</param>
        /// <param name="model">Initial value of the Model property.</param>
        /// <param name="productVersion">Initial value of the ProductVersion property.</param>
        public static C__MigrationHistory CreateC__MigrationHistory(global::System.String migrationId, global::System.Byte[] model, global::System.String productVersion)
        {
            C__MigrationHistory c__MigrationHistory = new C__MigrationHistory();
            c__MigrationHistory.MigrationId = migrationId;
            c__MigrationHistory.Model = model;
            c__MigrationHistory.ProductVersion = productVersion;
            return c__MigrationHistory;
        }

        #endregion

        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String MigrationId
        {
            get
            {
                return _MigrationId;
            }
            set
            {
                if (_MigrationId != value)
                {
                    OnMigrationIdChanging(value);
                    ReportPropertyChanging("MigrationId");
                    _MigrationId = StructuralObject.SetValidValue(value, false);
                    ReportPropertyChanged("MigrationId");
                    OnMigrationIdChanged();
                }
            }
        }
        private global::System.String _MigrationId;
        partial void OnMigrationIdChanging(global::System.String value);
        partial void OnMigrationIdChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Byte[] Model
        {
            get
            {
                return StructuralObject.GetValidValue(_Model);
            }
            set
            {
                OnModelChanging(value);
                ReportPropertyChanging("Model");
                _Model = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Model");
                OnModelChanged();
            }
        }
        private global::System.Byte[] _Model;
        partial void OnModelChanging(global::System.Byte[] value);
        partial void OnModelChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String ProductVersion
        {
            get
            {
                return _ProductVersion;
            }
            set
            {
                OnProductVersionChanging(value);
                ReportPropertyChanging("ProductVersion");
                _ProductVersion = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("ProductVersion");
                OnProductVersionChanged();
            }
        }
        private global::System.String _ProductVersion;
        partial void OnProductVersionChanging(global::System.String value);
        partial void OnProductVersionChanged();

        #endregion

    
    }
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="ProjectCodeModel", Name="Category")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class Category : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new Category object.
        /// </summary>
        /// <param name="id">Initial value of the Id property.</param>
        public static Category CreateCategory(global::System.Guid id)
        {
            Category category = new Category();
            category.Id = id;
            return category;
        }

        #endregion

        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Guid Id
        {
            get
            {
                return _Id;
            }
            set
            {
                if (_Id != value)
                {
                    OnIdChanging(value);
                    ReportPropertyChanging("Id");
                    _Id = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("Id");
                    OnIdChanged();
                }
            }
        }
        private global::System.Guid _Id;
        partial void OnIdChanging(global::System.Guid value);
        partial void OnIdChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                OnNameChanging(value);
                ReportPropertyChanging("Name");
                _Name = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("Name");
                OnNameChanged();
            }
        }
        private global::System.String _Name;
        partial void OnNameChanging(global::System.String value);
        partial void OnNameChanged();

        #endregion

    
        #region Navigation Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("ProjectCodeModel", "FK_dbo_BlogPosts_dbo_Categories_CategoryId", "BlogPosts")]
        public EntityCollection<BlogPost> BlogPosts
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<BlogPost>("ProjectCodeModel.FK_dbo_BlogPosts_dbo_Categories_CategoryId", "BlogPosts");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<BlogPost>("ProjectCodeModel.FK_dbo_BlogPosts_dbo_Categories_CategoryId", "BlogPosts", value);
                }
            }
        }

        #endregion

    }

    #endregion

    
}

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)

Share

About the Author

Morshed Anwar
Team Leader Adaptive Enterprise Limited (www.ael-bd.com)
Bangladesh Bangladesh
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 2 Nov 2012
Article Copyright 2009 by Morshed Anwar
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid