PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Strongly typed datased (it's datatable) as singleton

Reply

Strongly typed datased (it's datatable) as singleton

 
Thread Tools Rate Thread
Old 28-12-2006, 03:04 PM   #1
=?iso-8859-1?B?Smly7SBOZXV6aWw=?=
Guest
 
Posts: n/a
Default Strongly typed datased (it's datatable) as singleton


Hi,
I have problem with implementing strongly typed dataset (with tableadapter)
as singleton (A very large amount of data loaded at startup of winforms app,
I need this data at numbers of forms, and I need to bind this
dataset/datatable at designtime) . At first I realized implementing dataset
as singleton cause problems in design time. So I decided to implement
dataset's datatable as singleton.

Here is my code (dsSuau is strongly typed dataset):

partial class dsSuau
{
partial class TabSuauDataTable
{
private static TabSuauDataTable _tabSuauDataTable;

public static TabSuauDataTable getInstance()
{
if (TabSuauDataTable._tabSuauDataTable == null)
{
_tabSuauDataTable = new TabSuauDataTable();
}
return _tabSuauDataTable;
}

public void Fill()
{
dsSuauTableAdapters.TabSuauTableAdapter _tableAdapter = new
ageu.DataLayer.dsSuauTableAdapters.TabSuauTableAdapter();
_tableAdapter.Fill(_tabSuauDataTable);
}
}
}

Then I changed constructor visibility of TabSuauDataTable in designer.cs
file to private and changed some of dataset's method in designer.cs:

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
private void InitClass()
{
this.DataSetName = "dsSuau";
this.Prefix = "";
this.Namespace = "http://tempuri.org/dsSuau.xsd";
this.EnforceConstraints = true;
this.SchemaSerializationMode =
System.Data.SchemaSerializationMode.IncludeSchema;
//zmena
this.tableTabSuau =
ageu.DataLayer.dsSuau.TabSuauDataTable.getInstance();
if (this.tableTabSuau.DataSet != null)
{
this.tableTabSuau.DataSet.Tables.Clear();
}
base.Tables.Add(this.tableTabSuau);
}

This solution works, only one instance of datatable is created at startup of
application and is migrating throught forms and datasets.
But I have problem with VS 2005 designer. If I change dataset in design time
(add column to datatable for example), designer.cs file is overwritten and
my changes are lost. Are there any other ways to implement this singleton
behavior with desing time databinding to form, or some possibility to mark
my changed methods in designer.cs to prevent VS 2005 to overwrite them?

Thank you in advace

  Reply With Quote
Old 29-12-2006, 12:21 PM   #2
Jesús López
Guest
 
Posts: n/a
Default Re: Strongly typed datased (it's datatable) as singleton

You can define a specific dataview in such a way that every instance of this
dataview points to the singleton datatable instance. You use an instance of
the dataview to databind to windows controls at design time:

public class SuauDataView : DataView
{
public SuauDataView()
{
this.Table = dsSuau.TabSuauDataTable.getInstance();
}

}

Regards:

Jesús López



"Jirí Neuzil" <meuzil@seznam.cz> escribió en el mensaje
news:6D371ED8-C65F-43C6-B9E3-440C076D48F8@microsoft.com...
> Hi,
> I have problem with implementing strongly typed dataset (with
> tableadapter) as singleton (A very large amount of data loaded at startup
> of winforms app, I need this data at numbers of forms, and I need to bind
> this dataset/datatable at designtime) . At first I realized implementing
> dataset as singleton cause problems in design time. So I decided to
> implement dataset's datatable as singleton.
>
> Here is my code (dsSuau is strongly typed dataset):
>
> partial class dsSuau
> {
> partial class TabSuauDataTable
> {
> private static TabSuauDataTable _tabSuauDataTable;
>
> public static TabSuauDataTable getInstance()
> {
> if (TabSuauDataTable._tabSuauDataTable == null)
> {
> _tabSuauDataTable = new TabSuauDataTable();
> }
> return _tabSuauDataTable;
> }
>
> public void Fill()
> {
> dsSuauTableAdapters.TabSuauTableAdapter _tableAdapter =
> new ageu.DataLayer.dsSuauTableAdapters.TabSuauTableAdapter();
> _tableAdapter.Fill(_tabSuauDataTable);
> }
> }
> }
>
> Then I changed constructor visibility of TabSuauDataTable in designer.cs
> file to private and changed some of dataset's method in designer.cs:
>
> [System.Diagnostics.DebuggerNonUserCodeAttribute()]
> private void InitClass()
> {
> this.DataSetName = "dsSuau";
> this.Prefix = "";
> this.Namespace = "http://tempuri.org/dsSuau.xsd";
> this.EnforceConstraints = true;
> this.SchemaSerializationMode =
> System.Data.SchemaSerializationMode.IncludeSchema;
> //zmena
> this.tableTabSuau =
> ageu.DataLayer.dsSuau.TabSuauDataTable.getInstance();
> if (this.tableTabSuau.DataSet != null)
> {
> this.tableTabSuau.DataSet.Tables.Clear();
> }
> base.Tables.Add(this.tableTabSuau);
> }
>
> This solution works, only one instance of datatable is created at startup
> of application and is migrating throught forms and datasets.
> But I have problem with VS 2005 designer. If I change dataset in design
> time (add column to datatable for example), designer.cs file is
> overwritten and my changes are lost. Are there any other ways to implement
> this singleton behavior with desing time databinding to form, or some
> possibility to mark my changed methods in designer.cs to prevent VS 2005
> to overwrite them?
>
> Thank you in advace
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off