Re: Table relations across datasets

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Sahil Malik (contactmethrumyblog_at_nospam.com)
Date: 01/02/05


Date: Sun, 2 Jan 2005 05:58:23 -0500

Babu,

Yes it is possible to do. Though it is not straightforward. Let me explain.

There are two possible approaches to this problem.

Approach #a) Row Importing ---

Create a new datatable and populate it as per below --
DataTable dt = ds1.Tables[0].Clone();
foreach (DataRow dr in ds1.Tables[0].Rows)
{
  dt.ImportRow(dr);
}

Add dt to ds2, and setup a relationship.

Approach #b) Table shuffling --
DataTable dt = ds1.Tables[0] ;
ds1.Tables.Remove(0) ;
ds2.Tables.Add(dt) ;
// setup relation in ds2 now.
.. do ur work ..
.. when ur done ..
ds2.Tables.Remove(ds2) ; // you get the idea
ds1.Tables.Add(dt)

Pros and Cons of either approach --

Approach #a) ---
#1) Expensive for large tables.
#2) Good for repeated approaches
#3) Works great in multithreaded environments (as yours - well application
level/asp.net .. same concept).

Approach #b) ---
#1) Not expensive at all.
#2) Must use mutexes to prevent data corruption, or even proper logical
access.
#3) If you use mutexes, you'd get blocking situations.

.. To tell you the truth, point #2 and #3 might be incorrect - I believe
anything you stick in Application object gets serialized and cloned
everytime you request it back. I am fairly sure the ASP.NET cache does that.
You might have to write up a little test to verify #2 and #3, or you could
instead use ASP.NET cache. But if the object is being serialized and
deserialized to effectively clone it, either in Application object or Cache,
then it isn't much worse than Approach #a, except in approach #a you're
paying the penalty twice.

If I had to implement this, I'd use Approach #b, and instead of mutexes, I'd
create a static class with a private variable that holds the lookup
datatable, and wrap that in a public property and stick that into
Application instead. That way, you don't have to deal with complicated
thread synchronization issues (the framework takes care of it).

HTH,

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

"Babu M" <babupalladium1@yahoo.com> wrote in message
news:1104612801.861929.219500@c13g2000cwb.googlegroups.com...
> Hi all,
>
> May be this is an illogical question. But I will try anyway. Is there
> a way to create a relationship between two tables across datasets
> without violating the constraints? in other words, the primary table
> (with a foreign key) is in dataset1 and it's lookup table is in
> dataset2.
>
> I will explain why I need this setup. I have a Web application. I
> want to store all the lookup tables at the Application level and the
> business logic dataset at the Session level. The Session level dataset
> tables have foreign keys that need to map to these lookup tables. I
> don't want to populate these lookup tables at session level since it
> could choke the system resources if the number of sessions are huge.
> Any idea anybody?
>
> Babu.
>



Relevant Pages

  • Re: Table relations across datasets
    ... as far as I can see there is no serialization/deserialization of object ... > #3) If you use mutexes, ... >> want to store all the lookup tables at the Application level and the ... >> business logic dataset at the Session level. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re[3]: vn_fullpath() again
    ... How do you feel about small incremental improvements to name lookup? ... > - Don't purge intermediate but unused nodes from the name cache. ... since files can have hard links. ... > add a directory back-pointer to the parent of a file. ...
    (freebsd-hackers)
  • Re: [PATCH 00/37] Permit filesystem local caching
    ... The problem is that you have to do a database lookup of some sort, ... involving several synchronous disk operations. ... a fair bit better then BTRFS when the disk cache is cold. ... NFS, for example, wants to access a new inode, it first has to go to the ...
    (Linux-Kernel)
  • Re: [PATCH 00/37] Permit filesystem local caching
    ... CacheFiles does a disk lookup by taking the key given to it by NFS, ... a fair bit better then BTRFS when the disk cache is cold. ... Note that the get the filehandle, you have to do a LOOKUP op. ...
    (Linux-Kernel)
  • Re[2]: vn_fullpath() again
    ... - Don't purge intermediate but unused nodes from the name cache. ... that rapidly consume vnodes, this allows more vnodes to be recycled, so ... add a directory back-pointer to the parent of a file. ... valid (during the lookup), and of secondary importance after that. ...
    (freebsd-hackers)