Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Architecture> Repository Pattern w/ Self Servicing
 

Pages: 1
Architecture
Repository Pattern w/ Self Servicing
Page:1/1 

  Print all messages in this thread  
Poster Message
CardCoder502
User



Location:
Louisville
Joined on:
12-Dec-2016 23:24:58
Posted:
10 posts
# Posted on: 24-Jan-2017 22:34:44.  

I am working on a C# MVC 4 website, trying to trouble shoot an issue with data not refreshing properly.

SD.LLBLGEN.Pro.DQE.SqlServer.NET20
SD.LLBLGEN.Pro.LinqSupportClasses.NET35
SD.LLBLGEN.Pro.OrmSupportClasses.NET20
SD.LLBLGEN.Pro.QuerySpec

I was looking through our Repository pattern used in this project, and was curious about the static reference being held to LinqMetaData.... (I know this repository pattern below is fairly worthless, and exposes IQueryable)

Should we be holding a static reference to LinqMetaData?

Thanks



Code:

public class BaseRepository<T> : IRepository<T> where T : CommonEntityBase
    {
        protected static readonly LinqMetaData _metaData = new LinqMetaData();

        public virtual void Insert(T entity)
        {
            if (entity == null) throw new ArgumentNullException("Entity");
            entity.Save();
        }

        public virtual void Update(T entity)
        {
            if (entity == null) throw new ArgumentNullException("Entity");
            entity.Save();
        }

        public virtual void Delete(T entity)
        {
            if (entity == null) throw new ArgumentNullException("Entity");
            entity.Delete();
        }

        public virtual IQueryable<T> Table
        {
            get { return new DataSource<T>(_metaData.TransactionToUse, new ElementCreator(), _metaData.CustomFunctionMappings, _metaData.ContextToUse); }
        }
    }
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8034 posts
# Posted on: 26-Jan-2017 07:34:41.  
What LLBLGen version and runtime are you using? ( http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7718 )

Since v3.x, a lot of static methods in SelfServicing are moved out to DBUtils and Dao classes.

Why do you need to place this as an static member?


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
CardCoder502
User



Location:
Louisville
Joined on:
12-Dec-2016 23:24:58
Posted:
10 posts
# Posted on: 26-Jan-2017 23:50:02.  
daelmo wrote:
What LLBLGen version and runtime are you using? ( http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7718 )

Since v3.x, a lot of static methods in SelfServicing are moved out to DBUtils and Dao classes.

Why do you need to place this as an static member?


Project is C# ASP .NET MVC4, .NET 4.5
Code is generated using LLBLGen Pro version: 3.5
Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20

SD.LLBLGEN.Pro.ORMSupportClasses.NET20
Runtime Version: v2.0.50727
Version: 3.5.0.0

SD.LLBLGEN.Pro.LinqSupportClasses.NET35
Runtime Version: V2.0.50727
Version: 3.5.0.0

I did not write this code, so I'm not sure what the reason was behind having a static reference to LinqMetaData. I suspected that this static reference was causing some issues in my application. So, I am trying to figure out what the proper usage, and lifetime of a LinqMetaData object should be.

Should there be one instance of it per request in an MVC application, or is holding a static reference to it the right thing to do?

Thanks!
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8034 posts
# Posted on: 30-Jan-2017 06:19:48.  
You should instantiate a LinqMetaData every time you need one, unless it's necessary for other reasons.

In SelfServicing some static properties (as currently open connection, settings, connection strings) are hold in static members of Dao classes, but this is managed by LLBLGen Runtime. You only need to worry about use your LinqMetaData when you need one. IMHO there is not need to declare it as static in your repository.


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.