开发者

LazyLoad and ConnectionString

开发者 https://www.devze.com 2023-02-16 16:33 出处:网络
This is sort of penny for your thoughts type question. We code all our classes from scratch. For our business instances, connectionst开发者_开发技巧ring is part of the constructor. That is simple be

This is sort of penny for your thoughts type question.

We code all our classes from scratch. For our business instances, connectionst开发者_开发技巧ring is part of the constructor. That is simple because usually it is the only constructor param. When we load a record from the database and store it in an entity object... how should we remember the connectionstring? This is for lazyload purposes. Since we may be talking to more that one database instance of the same base database type. We need to know where we got the record from and to know where to lazyload related objects from.

I know this sounds like a simple question. We are trying to avoid codesmell.

Do we set a connectionstring in every constructor as a string to try to force it to be set? Do we store a reference to the business object that loaded the entity. Meanwhile, also thinking that we need to have an empty constructor when deserializing from xml for some cases.

Not experienced with this, but have thought of factories. That to get a new entity object must be through a factory where connectionstring must be proved.

This is not an explosed API, just something for the team to implement and adopt properly.

Some links/codeexamples would be great too. Thanks


Is this Entity Framework? Are you using POCOs? Can you take advantage of EF's built in lazy loading capabilities?

For what it's worth you can ask the context what database it is connected to with:

EntityConnection connection = myContext.Connection as EntityConnection;

if (connection != null)
    string db = connection.StoreConnection.Database;

That is probably not that helpful though.

0

精彩评论

暂无评论...
验证码 换一张
取 消