Namespace - LJCDBMessage
Syntax
C# |
public class DbRequest
|
Represents a database request.
(E)
Static
Constructor
#ctor
|
Initializes an object instance. |
#ctor
|
The Copy constructor. |
#ctor
|
Initializes an object instance with the supplied values. |
Data
Clone
|
Clones the structure of the object. |
Serialize
|
Serializes the object and returns the serialized string. |
Serialize
|
Serialize the object to the specified file. |
7 Methods
Properties
Example
The following example shows each step needed to retrieve data. Applications
should generally encapsulate much of this code in a table specific Manager class to
make application programming easier and cleaner.
A Manager class is the client code that creates a table specific DbQuery object.
It then serializes the DbRequest object into a request XML message to pass to the
DbService.Execute() method.
See examples in LJCDBServiceLib.DbService Methods Add, Retrieve, Load, Update and Delete.
The data service DbService can be hosted in a windows service or web service which
could run on a separate server machine.
C# |
using System;
using System.Collections.Generic;
using LJCNetCommon;
using LJCDBMessage;
using LJCDBServiceLib;
public class Person
{
public Int32 PersonId { get; set; }
public string Name { get; set; }
}
internal class Program
{
private static void Main(string[] args)
{
string personIDColumnName = "Person_ID";
string personIDDataPropertyName = "PersonId";
DbColumns personDefinition = new DbColumns()
{
{ personIDColumnName, personIDDataPropertyName, "Int32"},
{ "Name" } // Defaults to "String"
};
List<string> propertyNames = new List<string>()
{
"PersonId",
"Name"
};
var keyColumns = new DbColumns()
{
{ "PersonId", 1}
};
string tableName = "Person";
DbRequest dbRequest = new DbRequest("Select", tableName)
{
DataConfigName = "PersonData",
Columns = DbCommon.GetRequestColumns(personDefinition, propertyNames),
KeyColumns = DbCommon.GetRequestKeyColumns(keyColumns, personDefinition)
};
string request = dbRequest.Serialize();
DbService dbService = new DbService();
string result = dbService.Execute(request);
Person person = new Person();
DbCommon.SetObjectValues(result, person);
int id = person.PersonId;
string name = person.Name;
}
}
|
Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.