|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Strongly typed datased (it's datatable) as singletonI 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 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 Show quote "Jirí Neuzil" <meu***@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 > |
|||||||||||||||||||||||