Reputation: 1894
I'm working on an older web site application
in C#, ASP.NET, which is now running on 4.7.2
The WebControlling.xsd
contains the definitions, constraints and operations on the dataset with tables
and table adapters
.
For all the older tables there is a class operating on it as well as a view.
.App_Code
- BLL
- - Foo.cs
- DAL
- - WebControlling.xsd
.Portal
- Foo
- - Foos.aspx
- - FooAdd.aspx
- - FooEdit.aspx
The adapter has the regular Fill
and GetData
operations on it. Is there a way to generate some, if not all of this structure from the .xsd
alone?
The other option I see is to copy and edit an existing class (like Foo.cs
), but since all classes look the same I feel like they could be generated. I think it would be easier to use tooling if changes to this are necessery since it's less likely to fail and / or forget changes in some places.
This is what a Foo.cs
looks like:
[System.ComponentModel.DataObject]
public class Foo
{
private FooTableAdapter _fooAdapter;
public Foos()
{
}
protected FooTableAdapter Adapter
{
get
{
if (_FoosAdapter == null) _FoosAdapter = new FoosTableAdapter();
return _FoosAdapter;
}
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, true)]
public WebControlling.FoosDataTable GetFoos()
{
return Adapter.GetFoos();
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
public WebControlling.FoosDataTable GetFooByID(Guid ID)
{
return Adapter.GetFooByID(ID);
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
public WebControlling.FoosDataTable GetFoosByCountryID(Guid ID, bool viewAll)
{
String sViewAll = viewAll ? "1" : "0";
return Adapter.GetFoosByCountryID(ID, sViewAll);
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
public WebControlling.FoosDataTable GetOpenFoosByCountryID(Guid ID, bool viewAll)
{
String sViewAll = viewAll ? "1" : "0";
return Adapter.GetOpenFoosByCountryID(ID, sViewAll);
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
public WebControlling.FoosDataTable GetFoosWithForeignValues()
{
return Adapter.GetFoosWithForeignValues();
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
public WebControlling.FoosDataTable GetFooByIDWithForeignValues(Guid ID)
{
return Adapter.GetFooByIDWithForeignValues(ID);
}
public bool AddFoo(System.Guid FooID, System.String Name, Int32 FooYear, System.Boolean IsValid)
{
WebControlling.FoosDataTable Foos = new WebControlling.FoosDataTable();
WebControlling.FoosRow Foosrow = Foos.NewFoosRow();
Foosrow.ID = Guid.NewGuid();
Foosrow.FooID = FooID;
Foosrow.Name = Name;
Foosrow.FooYear = FooYear;
Foosrow.IsValid = IsValid;
Foos.AddFoosRow(Foosrow);
int rowsAffected = Adapter.Update(Foos);
return rowsAffected == 1;
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool UpdateFoo()
{
...
}
public bool UpdateFooState(System.Guid ID, bool IsClosed)
{
...
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Delete, true)]
public bool DeleteFoo(Guid ID)
{
...
}
}
Seems generated to me.
Edit:
This question has interesting insight into generating classes from .xsd
. My question differs because:
.aspx
Upvotes: 0
Views: 179