The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

Archive for the 'HowTo' Category

How to use the SQL-99 with clause.

Posted by Gerhard Stephan on 7th December 2007

The SQL-99 with clause is used for substitute where conditions, if you have a sql with multiple sub selects. Puhh. It’s Hard to explain. But: Imagine you have a sql query like the following one:

 

select * from tp_anwender where anwender in

 (select anwender from tp_entries where Computer = ‘xyz’ /* more queries */ and Rechte = 1 union all

  select anwender from tp_entries where Computer = ‘xyz’ /* more queries */ and Rechte = 2 union all

  select anwender from tp_entries where Computer = ‘xyz’ /* more queries */ and Rechte = 3);

 

Sure. It’s not the best example. But you can see, that the where conditions in the sub selects are almost the same. Only the "Rechte" column differs. This can be very good optimized, when using the with clause.

 

with sub01 as (

      select * from tp_entries e where Computer = ‘xyz’ /* more queries */

)

select * from tp_anwender where anwender in

 (select anwender from sub01 where Rechte = 1 union all

  select anwender from sub01 where Rechte = 2 union all

  select anwender from sub01 where Rechte = 3);

 

To build such queries, the AdFactum ObjectMapper .NET does now support the "with clause" for Oracle and the Sql Server. Microsoft Access and SqlServerCE won’t support the with clause.

 

WithClause subClause = new WithClause("sub01", typeof(TpEntries),

    new AndCondition(typeof (TpEntries), "Computer", "xyz"));

 

SubSelect anwender01 = new SubSelect(typeof(TpEntries), "Anwender",

    new AndCondition(typeof(TpEntries), "Rechte", 1),

    new TableReplacement(typeof(TpEntries), "sub01"));

 

SubSelect anwender02 = new SubSelect(typeof(TpEntries), "Anwender",

    new AndCondition(typeof(TpEntries), "Rechte", 2),

    new TableReplacement(typeof(TpEntries), "sub01"));

 

ICondition selection = new ConditionList( subClause,

    new InCondition(typeof(TpAnwender), "Anwender"

    new UnionAll(activityId01, activityId02)));

 

using (AdFactum.Data.ObjectMapper mapper = OBM.CreateMapper(Connection))

{

    int result = mapper.Count(typeof(TpAnwender), selection);

    …

)

 

If you have any questions to this new functionality, don’t hesitate to ask.

That’s all for now folks.

 

Wish you a great weekend.

 

Cheers

- Gerhard

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | 1 Comment »

How to check if a property has been changed since last loading the object.

Posted by Gerhard Stephan on 20th September 2007

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | No Comments »

How to use Generics with the AdFactum ObjectMapper .NET

Posted by Gerhard Stephan on 13th September 2007

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | No Comments »

How to get the primary key of an aggregated entity when doing a flat load of the parent.

Posted by Gerhard Stephan on 16th August 2007

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | No Comments »

How to store binary data (blob)

Posted by Gerhard Stephan on 23rd April 2007

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | No Comments »

How to build sql queries

Posted by Gerhard Stephan on 22nd January 2007

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | No Comments »

How to do bind collections

Posted by Gerhard Stephan on 24th August 2006

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...

Posted in HowTo | 2 Comments »

How to setup database tables instantly

Posted by Gerhard Stephan on 9th August 2006

1 Votes | Average: 3 out of 51 Votes | Average: 3 out of 51 Votes | Average: 3 out of 51 Votes | Average: 3 out of 51 Votes | Average: 3 out of 5 (1 votes, average: 3 out of 5)
Loading ... Loading ...

Posted in HowTo | No Comments »