473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Table bloat in Linq-SQL

var db = new MyDb(connString);

causes creation of all objects corresponding to all tables in database.

Database contains 500 tables.
Application accesses only few tables at a time.

Creating large number of objects which are not used is bad design.

How to force Linq-SQL to create table objects only when they are first
accessed ?

Andrus.
Nov 10 '07 #1
7 2639
I think this is done to be able to create queries at runtime properly
from the expression trees. (otherwise the context will run into unknown
table references).
pgsqlmetal generates code:

public readonly MTable<CustomerCustomers;

public MyDb(string connStr): base(connStr) {

Customers = new MTable<Customer>(this);
.....

}

Is it reasonable to replace Customer field to delayed instantion property
like

public readonly MTable<Customercustomers;

public readonly MTable<CustomerCustomers {
get { if ( customers=null )
customers = new MTable<Customer>(this);
return customers;
}

Why would you want to create these wrappers at runtime? Because that
way you can't program against them.
My application should run in a lot of customer sites.
Customers may have added additional columns to tables in database.
I need to edit those columns in grid.
So I need to retrieve those properties from database also.

Andrus.

Nov 11 '07 #2
Jon,
I think he means the Table<T- on the RDBMS there wouldn't be
anything triggering assemblies being loaded etc (typically, anyway).
But yes, some more clarity would be nice :)
I'm sorry I was not clear.

Table<Tobject instantion causes assembly containing type T to be loaded.

So my issue is: is it possible and reasonable to change sqlmetal generated
code
so that it does not create tables in Data Context constructor?

Is it possible and reasonable to move table creation to table property
getter by implementing getter like

public readonly MTable<CustomerCustomers {
get { if ( customers=null )
customers = new MTable<Customer>(this);
return customers;
}

Will Linq-SQL work well in this case in design and run times ?

Or will only reference to Table<Tin assembly cause assembly containing
type T to be loaded ?

If so I think I will create whole extended properties assembly at runtime
and load it fully. If this causes perfomace decrease I hope I can cache this
extented assembly in isolated storage.

I havent seen any .NET application with uses background assembly loading at
startup like windows logon.

Andrus.
Nov 12 '07 #3
Andrus <ko********@hot.eewrote:
I think he means the Table<T- on the RDBMS there wouldn't be
anything triggering assemblies being loaded etc (typically, anyway).
But yes, some more clarity would be nice :)

I'm sorry I was not clear.

Table<Tobject instantion causes assembly containing type T to be loaded.
Right, I can understand that.
So my issue is: is it possible and reasonable to change sqlmetal generated
code so that it does not create tables in Data Context constructor?
It may be possible, but it sounds like a bad idea to me. When you
deviate a long way from standard practice, you tend to run into all
sorts of difficulties and very few people are able to help you out.
That's a general observation, not one about LINQ to SQL in particular.
Is it possible and reasonable to move table creation to table property
getter by implementing getter like

public readonly MTable<CustomerCustomers {
get { if ( customers=null )
customers = new MTable<Customer>(this);
return customers;
}
At that point you'd need to know the real details of when the CLR loads
any particular type. It's not something I've ever investigated in
*great* detail, but relying on particular behaviour seems like a bad
idea to me - not because it won't work, but because it'll be very
difficult to maintain.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 12 '07 #4
Here is an example of how you can add properties to an object
at runtime.
Thanks, but we've already had that conversation - see Andrus's note
above:
Unfortunatley LinQ-SQL does not support TypeDescriptor define properties.
Marc

Nov 22 '07 #5
Here is an example of how you can add properties to an object at
runtime.

http://www.spikesolutions.net/ViewSo...2-ac5448180a65
Thankyou.

Googling for Custom Property Framework returns no exact matches.

Where to find demo and/or trial versions of this framework ?
Where to find more information about the technology used ?

Andrus.
Nov 22 '07 #6
>Unfortunatley LinQ-SQL does not support TypeDescriptor define properties.

Marc,

why do you think it uses TypeDescriptor ?
Maybe it uses dynamic compiling or even direct IL code emit to create
wrapper class ?

In this case it may support LinQ.

Andrus.
Nov 22 '07 #7
why do you think it uses TypeDescriptor ?

By reading the description. The only real way to add extra properties
(in the normal sense) at runtime is via TypeDescriptor. I know you
have this hybrid app-startup-time/compile-time thing going on, but
that isn't really runtime in the normal sense. Of course, since this
ships with custom UI it is possible that it *doesn't even* go via
TypeDescriptor, but just uses something like an "object this[string
name]" indexer and a lot of UI work...

You're welcome to pay $20 to get the code, but my *suspicion* is that
you'll be mildly disappointed. Up to you.

Marc
Nov 23 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
7
by: Danny J. Lesandrini | last post by:
I know this has been discussed before, as I've seen the Google posts, but they all leave me with an unanswered question: Does my DAO code executed in the front end cause the back end to bloat?...
11
by: BillCo | last post by:
I'm using a backend that's been around for years before I joined the company. It kind of grew exponentially and has some design problems including large unused tables some temporary tables. It...
5
by: MLH | last post by:
I've read a number of posts over the years that dealt with the issue of database bloat. I'm wondering if anyone has determined exactly what information comprises the bloat when it does occur. Has...
2
by: gordonmcconnell | last post by:
I have a table that I would like images to be stored to. I would like the users to be able to add images and information about the images to this table through the use of a form. I want them to...
48
by: Tony | last post by:
How much bloat does the STL produce? Is it a good design wrt code bloat? Do implementations vary much? Tony
2
by: Ronald S. Cook | last post by:
So I have a table "Employee" and wish to have a business class "Employee". This was possible before LINQ. But now that I am generating a .dbml for the LINQ DataContext, it "takes over" those names...
2
by: Joey | last post by:
I am querying a DataSet with LINQ. I am running into a problem when trying to construct my query because in the "from" clause I do not know the table name (range variable) until runtime. Possible...
0
by: \Ji Zhou [MSFT]\ | last post by:
Hello Ashutosh, I see your points. As to your two new concerns, I am give the detailed comments in the following. 1. Is it possible to achieve this result without calling Update on the route...
2
by: Andy B | last post by:
How would you find out if a linq table has 0 rows in it? I have this code: NewsContext.V_News() '*** linq table to be tested for 0 rows Any ideas?
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.