473,772 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2652
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<Customer Customers;

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<Customer customers;

public readonly MTable<Customer Customers {
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<Customer Customers {
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<Customer Customers {
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.co m>
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
>Unfortunatle y 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
4008
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 as well. To support thin-template, I need to make virtual function as inline. Now, I know that compiler would generate an out-of-line copy when it
7
2712
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? (May also substitute UPDATE and/or DELETE queries for DAO code.) I was just brought on to a project with Access 97 where the all data is kept on the server. It doubles in size each day, from 80 mb to 160 mb. The data file contains only tables...
11
4082
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 compacts to 150Mb, but after a day it's up to 300Mb and it gros steadily from there. I need to: (a) reduce the size (b) reduce the bloat factor Apart from moving the temporary tables to front end (which can't possibly account for all of the this...
5
6714
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 anyone ever looked into that and arrived at a conclusion? Part-2 of the question is "Under what circumstances does MS Access database bloat occur and what can be done to circumvent it?"
2
2468
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 simply be able to click a button, find the image on their computer, and have that stored into the table. I know if it is not linked the database will bloat, so how would I do this via linking? If you could point in the right direction with...
48
2639
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
1143
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 for its classes. I'd hate to have to name my business classes "EmployeeClass" or some other non-ideal convention. Any thoughts? Thanks,
2
4810
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 table names might include "SomeTable1" or "SomeTable236" etc... Unfortunately when I try to use something like "from SomeTable + MyChangingNumber.ToString() in..." in my from clause it does not work. How can I set this up to use a range variable...
0
1958
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 table? I want to give the user an option to save/reject the changes. Yes, we can achieve the objective without calling the Update function on the route table. The necessary thing we need to do is updating the
2
3760
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?
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.