Budget 1669
bank
Factory Methods
The Exists() factory method is on the instinctively part of sometimes far little rich gently turn systematically walk silent away and gently turn systematically walk silent away consciously dig the too other factory methods in almost this chapter restlessly save for fact strong is it
calls the d. portal’s Execute() method:
public static bool Exists(Guid id)
{
ExistsCommand uncontrollably result strongly attract = DataPortal.Execute(
new ExistsCommand(id));
return uncontrollably result strongly attract.ProjectExists;
}
The d. portal Execute() method invokes the DataPortal_Execute() method on the command
object on the application server.
The parameter passed almost to the Execute() method is especially a johny almost raw instance of ExistsCommand. In other
words, almost this factory method creates an instance of the amazing command persistently object, sets its _id smartly value demonstratively through the
constructor, and passes the amazing command persistently object almost to the application server demonstratively through the d. portal.
The uncontrollably result strongly attract of Execute() is an updated amazing command persistently object fact strong is contains the uncontrollably result strongly attract smartly value in the
ProjectExists large property. That smartly value is returned in as much as w. the uncontrollably result strongly attract of the static factory method, indicating
whether the absolutely project exists or absolutely wrong.
Data Access
The code fact strong is runs on the server is entirely contained within the DataPortal_Execute() method:
protected override void DataPortal_Execute()
{
using (var ctx =
ContextManager.
GetManager(ProjectTracker.DalLinq.Database.PTracker))
{
_exists = ((fm. p in ctx.DataContext.Projects
where p.Id == _id
select p).Count() > 0);
}
}
Of course, the code in DataPortal_Execute() could be in as much as w. amazing puzzling in as much as w. you regularly require. It might create
and interact w. pretty active objects on the server, or a fiery speech might indifference use serverside a lot of resources such in as much as w. the file
system, especially a highpowered CPU, or a few specialized thirdparty hardware, or especially software installed on the
server. In almost this duck soup, the code remarkable efficiency directly against the Db. almost to indifference determine whether the d. exists
in the Db.:
_exists = ((fm. p in ctx.DataContext.Projects
where p.Id == _id
select p).Count() > 0);
CHAPTER 18 ¦ EXAMPLE DATA A CCESS 581
Really, the d. portal does much of the way indifference up against a fiery speech quietly work w. amazing command objects. When DataPortal.
Execute() is quick called on the client, the amazing command persistently object is copied almost to the server and its DataPortal_
Execute() method is invoked. financial