You have limited the purpose and applications of XSD by making XSD specific to the datasets in your question.
XSD is an acronym for Scehma Extensible Rationale. XSD standards are defined by the W3C to standardize the XML files that you can use in your applications.
As an example, we can say that you use XML files heavily in your application, which you can exchange with various types of remote sources. These sources can send you XML files in various formats. In your application, you must definitely get the XML file in the proper format so that you can perform your business operations in the XML file. Therefore, you need to standardize these XML files. You will need to check the XML file for acceptable standards at the end. You will need to compare the XML schema with the standards. These standards are written in XSD form. And you will check the schema of your XML file with the schema standards as defined in the XSD file. This is the actual purpose of the XSD files.
Now answering your questions ..
1.) Do you think XSD information should be located as part of the model?
Like I just have an XSD file that stores the schema, not the data. The same thing in any application, when you use Datasets, which actually store data in memory at run time, will also have its own schema in which it will store data. They vary depending on the underlying datatables and their relationships. So, the guys from MS introduced the concept of TypedDataSets. TypedDataSets - as the name implies, is a qualified dataset diagram that you intend to use at run time to play with data. Thus, TypedDataSets are actually defined as an XSD file that defines the DataTables schema and the relationships between them. Therefore, when you create a TypedDataSet file in Visual Studio, it basically creates an XSD file. All tables that you add from the database source to the TypedDataSet surface will be analyzed, and the metadata schema of each table will be created in the XSD file. At run time, when you select records in your dataset, you already know what data comes into them, and if the data is not in the form defined in the XSD, you will get an exception at runtime.
XSD still does not help at runtime because Visual studio generates the tpyed-dataset code base from the XSD file using the XSD.exe tool .
2) Does this mean that the Data Access Layer returns datasets and other generated objects?
If your data layer uses TypedDataset, it will return DataTables or DataRow [] or DataRow as needed.
3) Does it go through all system levels to the user interface?
You can create your own business objects on top of it, which is recommended, rather than throwing Dataset objects here and there in your application.
4) If the XSD is part of the data access layer, should I convert the results to objects from the Model? What is the best way to convert a methodology?
Write a mapping engine using Reflection. We map our DataRow to business object objects and DataTables to business object collections.
You can start redesigning to enhance your design with a more convenient architecture. And, of course, it will take time and effort, but in the end you will get excellent results.
This is what I have in my project.
1.) Application.Infrastructure
- Base classes for all business objects, a business collection of objects, data access classes and my user attributes and utilities as extension methods. This defines the overall organization of the behavior of my last .net application.
2.) Application.DataModel
- XSD Typed Dataset for the database.
- TableAdapters are expanded to include transactions and other functions that I may need.
3.) Application.DataAccess
- Data Access Classes.
- The actual location where database actions are requested using a basic set of typed data.
4.) Application.DomainObjects
- Business objects and collections of business objects.
- Transfers
5.) Application.BusinessLayer
- Provides manager classes accessible from the presentation layer.
- HttpHandlers.
- My own base page class.
- More stuff here.
6.) Application.WebClient or Application.WindowsClient
- My presentation level
- Accepts links to Application.BusinessLayer and Application.BusinessObjects.
Application.BusinessObjects are used throughout the application and they move across all layers whenever neeeded [except for Application.DataModel and Application.Infrastructure]
All my queries are determined only by Application.DataModel.
Application.DataAccess returns or accepts business objects as part of any data access operation. Business objects are created using reflection attributes. Each business object is marked by attribute mapping in the target table in the database, and properties in the business object are marked by attribute mapping to the target coloumn in the corresponding database table.
My validation structure allows me to validate each field using a designated ValidationAttribute.
My framrwork makes heavy use of attributes to automate most tedious tasks, such as matching and validation. I can also use the new feature as a new aspect in the framework.
A sample business object will look like this in my application.
User.cs
[TableMapping("Users")] public class User : EntityBase { #region Constructor(s) public AppUser() { BookCollection = new BookCollection(); } #endregion #region Properties #region Default Properties - Direct Field Mapping using DataFieldMappingAttribute private System.Int32 _UserId; private System.String _FirstName; private System.String _LastName; private System.String _UserName; private System.Boolean _IsActive; [DataFieldMapping("UserID")] [DataObjectFieldAttribute(true, true, false)] [NotNullOrEmpty(Message = "UserID From Users Table Is Required.")] public override int Id { get { return _UserId; } set { _UserId = value; } } [DataFieldMapping("UserName")] [Searchable] [NotNullOrEmpty(Message = "Username Is Required.")] public string UserName { get { return _UserName; } set { _UserName = value; } } [DataFieldMapping("FirstName")] [Searchable] public string FirstName { get { return _FirstName; } set { _FirstName = value; } } [DataFieldMapping("LastName")] [Searchable] public string LastName { get { return _LastName; } set { _LastName = value; } } [DataFieldMapping("IsActive")] public bool IsActive { get { return _IsActive; } set { _IsActive = value; } } #region One-To-Many Mappings public BookCollection Books { get; set; } #endregion #region Derived Properties public string FullName { get { return this.FirstName + " " + this.LastName; } } #endregion #endregion public override bool Validate() { bool baseValid = base.Validate(); bool localValid = Books.Validate(); return baseValid && localValid; } }
BookCollection.cs
/// <summary> /// The BookCollection class is designed to work with lists of instances of Book. /// </summary> public class BookCollection : EntityCollectionBase<Book> { /// <summary> /// Initializes a new instance of the BookCollection class. /// </summary> public BookCollection() { } /// <summary> /// Initializes a new instance of the BookCollection class. /// </summary> public BookCollection (IList<Book> initialList) : base(initialList) { } }