Re: Table relations across datasets
From: Sahil Malik (contactmethrumyblog_at_nospam.com)
Date: 01/02/05
- Next message: Sahil Malik: "Re: Validating data."
- Previous message: Cor Ligthert: "Re: Is Whidbey the beginning of the end for the developer ?"
- In reply to: Babu M: "Table relations across datasets"
- Next in thread: Babu Mannaravalappil: "Re: Table relations across datasets"
- Reply: Babu Mannaravalappil: "Re: Table relations across datasets"
- Reply: Chris Taylor: "Re: Table relations across datasets"
- Messages sorted by: [ date ] [ thread ]
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.
>
- Next message: Sahil Malik: "Re: Validating data."
- Previous message: Cor Ligthert: "Re: Is Whidbey the beginning of the end for the developer ?"
- In reply to: Babu M: "Table relations across datasets"
- Next in thread: Babu Mannaravalappil: "Re: Table relations across datasets"
- Reply: Babu Mannaravalappil: "Re: Table relations across datasets"
- Reply: Chris Taylor: "Re: Table relations across datasets"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|