Best Practice for LinqMetaData instances

Posts   
 
    
RobertPhoenix avatar
Posts: 20
Joined: 14-Aug-2006
# Posted on: 17-Jun-2017 02:09:21   

Apologies if this is answered somewhere, but I could not find it.

Should I create a new instance of LinqMetaData each time I have a query or a set of queries in the same module ?

Or can I create one instance for the application and use the same instance every time.

Clearly I would need to create a new instance if I wanted to pass in a transaction. (But again I can't find the formal definition for LinqMetaData constructors, so I don't know if there are other options which would likewise need a specific instance)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Jun-2017 08:11:24   

You should instantiate a LinqMetaData every time you need one, unless it's necessary for other reasons. It's very cheap to create and destroy them.

In the adapter scenario the adapter needs to dispose the connection object, and it does that, so no dispose call is needed. It by default closes a connection after an action, which gives the underlying connection object back to the pool. The adapter will dispose the active connection object when it closes it. For SelfServicing is not that different, a connection is open and closed for each call, but remember that the LinqMetaData is not responsible of disposing the connection. LinqMetaData is a class for the construction of Linq queries.

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 Support Team
RobertPhoenix avatar
Posts: 20
Joined: 14-Aug-2006
# Posted on: 19-Jun-2017 20:11:00   

Thanks for the complete answer. I'll create a new LingMetaData every time I make a query.

I was also interested in the links at the bottom of your email, hoping for more insights, but the link to llblgening appears to be broken (just in case you did not know)

Regards,

Robert.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Jun-2017 00:09:10   

Hi Robert,

Yes, I'm migrating the content of my blog. Hopefully it's live in a couple of days wink

David Elizondo | LLBLGen Support Team