Thursday, 19 February 2009

Group By in dodatne SQL funkcije


Opis:
Kako uporabiti Group by ali podobne funkcije nad podatki, ki jih pozanamo iz SQL-a. (Sum, Count, max, min,.....). 

Rešitev:
Narediti moramo objekte, ki dedujejo od Analise in AnaliseList. Implementirati lastnosti, ki so potrebne na teh objektih uporabiti public konstruktor brez parametrov. Seznam polj katere bomo poterebovali iz podatkovne baze, ter javne lastnosti le teh. Enako kot na vseh ostalih PBBusinessBase objektih. AnaliseList je enak kot drugi List objekti, doda se samo implementacija kriterija, ki je opisana spodaj v primeru. Obvezna uporaba Transformer Objekta, ker nam takšen način uporabe kriterija vrne Array[], ki ga je potrebno transformirat. Za to poskrbi Transformer objekt, ki uporablja javne lastnosti objekta in javni konstruktor. Obvezno moramo poskrbeti da uporabimo Alias, ki je enak imenu lastnosti.

Primer:
var projections = Projections.ProjectionList()
                        .Add(Projections.Sum("Qty"),"Qty")
                        .Add(Projections.Max("ProductName"), "ProductName")
                        .Add(Projections.GroupProperty("ProductId"), "ProductId");                    
_iCriteria.SetMaxResults(5).AddOrder(Order.Desc("Qty"));_iCriteria.SetProjection(projections).SetResultTransformer(Transformers.AliasToBean(typeof(WOrderItemAnalise)));

Zadržki:


Vir:
http://japikse.blogspot.com/2009/02/using-projections-and-transformers-in.html

Monday, 16 February 2009

Brisanje zapisov [CSLA]

Remove,Contains, and ContainsDeleted
Collections that inherit from BusinessListBase automatically have Remove(), Contains(), and
ContainsDeleted() methods. Each of these accepts a reference to a child object as a parameter, and
often that is sufficient.
For this collection, however, it turns out that the UI code in Chapters 9 and 10 is much simpler
if it is possible to remove or check for a child object based on a resource Id property value rather
than a child object reference. To provide this capability, each of these three methods is overloaded
with a different implementation. For instance, here’s the Remove() method:
public void Remove(int resourceId)
{
foreach (ProjectResource res in this)
{
if (res.ResourceId == resourceId)
{
Remove(res);
break;
}
}
}

This method accepts the resourceId value as a parameter, and that value is used to locate the child
object (if any) in the collection. The Contains() and ContainsDeleted() overloads follow the same basic
approach.
Not all collections will need overloads of this type, but such overloads are often useful to simplify
the use of the collection and reduce code in the UI.