Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / January 2005

Tip: Looking for answers? Try searching our database.

strongly-typed dataset datatable constructor's are marked as inter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
theWizK - 28 Jan 2005 18:11 GMT
Hello all.

I have noticed that when I generate a strongly-typed dataset from an xml
schema that the DataTables that are generated have their constructors marked
as internal.  What this means is when I try to instantiate one of the
strongly-typed tables from this  dataset from a different assembly, I cannot.
Let me provide examples...

If I have a simple dataset like this:

<?xml version="1.0" ?>
<xs:schema id="WebReportPersonalityDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
 <xs:element name="WebReportPersonalityDataSet" msdata:IsDataSet="true">
   <xs:complexType>
     <xs:choice maxOccurs="unbounded">
       <xs:element name="Personality" msprop:typedName="Personality"
msprop:typedPlural="Personalities">
         <xs:complexType>
           <xs:sequence>
             <xs:element name="PeopleID" type="xs:int" minOccurs="0" />
             <xs:element name="Last_Name" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="First_Name" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="Middle_Name" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="FormattedName" type="xs:string"
minOccurs="0" msprop:nullValue="_null" />
             <xs:element name="Confidence" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="DocNum" type="xs:int" minOccurs="0" />
             <xs:element name="RefDate" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="Title" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="KeyWords" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="entered_by" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="reviewed_by" type="xs:string" minOccurs="0"
msprop:nullValue="_null" />
             <xs:element name="ApprovedForUse" type="xs:string"
minOccurs="0" msprop:nullValue="_null" />
             <xs:element name="NotApprovedForUse" type="xs:string"
minOccurs="0" msprop:nullValue="_null" />
             <xs:element name="ApprovedForPub" type="xs:string"
minOccurs="0" msprop:nullValue="_null" />
             <xs:element name="rowguid" msdata:DataType="System.Guid,
mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
           </xs:sequence>
         </xs:complexType>
       </xs:element>
     </xs:choice>
   </xs:complexType>
 </xs:element>
</xs:schema>

and I run the xsd.exe utility on it, I get a source code file that looks
something like this:

--snip--
//
// This source code was auto-generated by xsd, Version=1.1.4322.573.
//
namespace WebReports.Data {
--snip--

       [System.Diagnostics.DebuggerStepThrough()]
       public class PersonalitiesDataTable : DataTable,
System.Collections.IEnumerable {
--snip--
           internal PersonalitiesDataTable() :
                   base("Personality") {
               this.InitClass();
           }

           internal PersonalitiesDataTable(DataTable table) :
                   base(table.TableName) {
               if ((table.CaseSensitive != table.DataSet.CaseSensitive)) {
                   this.CaseSensitive = table.CaseSensitive;
               }
               if ((table.Locale.ToString() !=
table.DataSet.Locale.ToString())) {
                   this.Locale = table.Locale;
               }
               if ((table.Namespace != table.DataSet.Namespace)) {
                   this.Namespace = table.Namespace;
               }
               this.Prefix = table.Prefix;
               this.MinimumCapacity = table.MinimumCapacity;
               this.DisplayExpression = table.DisplayExpression;
           }
--snip--
       }
--snip--
}

As you can see, the PersonalitiesDataTable class is public, but the
constructors are both marked internal. which means that I can only
instantiate one of these tables directly, from the assembly that  contains
this strongly-typed dataset.  This is a problem when I've got this dataset as
well as all of my database libraries in one assembly, and I try to use them
from another assebmly (such as my web project).

Has anyone else had problems with this?  Is there a way to change this
behavior?  My initial thoughts are that the only way I can get around this it
to generate the dataset (in VS.NET) classes and then remove the Custom Tool
Command "MSDataSetGenerator" so that it does not get re-generated.  This is a
pain in the rear, however, if I ever want to add or remove columns from the
dataset, or make other modifications.  It also means that I've got to check
in this generated source code into source control (which I normally do not
do).  Are there any attributes that I can add to the dataset (like some of
the other msdata: and msprop: namespace attributes) to make these public by
default?

Thanks in advance or any suggestions or solutions to my  problem.

Kendal.
almscl2@yahoo.com - 30 Jan 2005 13:07 GMT
There is a way around this problem. Generate proxy class inside your
dll that creates the table and passes it back to the calling function.

Something like this:

public class Proxy
{
public static PersonalitiesDataTable GetPersonalitiesDataTable ()
{
PersonalitiesDataTable ret = new PersonalitiesDataTable();
return ret;
}
}

and use the static methods of this class from your client code instead
of trying to instantiate PersonalitiesDataTable directly.

By the way, my company also has a product calls WF BusinessComponent
that you can use to load a XML schema to a dataset at design-time. Take
a look at http://www.wirefactor.com. The production release will be out
soon.

Thanks,
-Al

> Hello all.
>
> I have noticed that when I generate a strongly-typed dataset from an xml
> schema that the DataTables that are generated have their constructors marked
> as internal.  What this means is when I try to instantiate one of the

> strongly-typed tables from this  dataset from a different assembly, I cannot.
>  Let me provide examples...
[quoted text clipped - 10 lines]
>       <xs:choice maxOccurs="unbounded">
>         <xs:element name="Personality" msprop:typedName="Personality"

> msprop:typedPlural="Personalities">
>           <xs:complexType>
[quoted text clipped - 14 lines]
> msprop:nullValue="_null" />
>               <xs:element name="Title" type="xs:string" minOccurs="0"

> msprop:nullValue="_null" />
>               <xs:element name="KeyWords" type="xs:string" minOccurs="0"
[quoted text clipped - 81 lines]
>
> Kendal.
theWizK - 31 Jan 2005 15:01 GMT
Absolutely.  Thanks for smacking me into reality.  I've done this before in
the Java world, but didn't even think about it.  Guess sometimes you're
thinking to hard about the problem, and you miss the simplest solutions.

Thanks a bunch, Al.

Kendal

> There is a way around this problem. Generate proxy class inside your
> dll that creates the table and passes it back to the calling function.
[quoted text clipped - 20 lines]
> Thanks,
> -Al

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.