The ObjectMapper .NET Project

Official blog of the AdFactum ObjectMapper .NET

New Release – AdFactum ObjectMapper .NET 2.3.3903.0

Posted by Gerhard Stephan on April 3rd, 2009

Today I release a small patch that fixes some bugs in the ObjectMapper .NET.

The first is, that the ObjectMapper .NET can now extend SubSelect in order to use GROUP BY within the SubSelects. That is for example, if you use Projections within a SubSelect. In addition to that I solved a failure that ended up in wrong sql creation, because the property projection had been wrong mapped. That was also a problem when using SubSelects.

Furthermore I fixed a long time undetected bug. The WriteSchemaDif Method of the ObjectMapper class had been wrongly mapped the corresponding WriteSchemaDif Method of the persister, which leaded to wrong results when calling the WriteSchemaDif Method of the ObjectMapper class.

And last but not least, the Orm API Relations have been adjusted to get a better understanding for human people who read the data.

That’s all for now. Enjoy the new version and the perfect weather outside.

Cheers
- Gerhard


Posted in Releases | No Comments »

New Release – AdFactum ObjectMapper .NET 2.3.3815.0

Posted by Gerhard Stephan on March 16th, 2009

It’s time to release a small patch that fixes two bugs regarding Projection and Grouping SQLs.

The first is a bug that appeared when trying to create a SQL statement that has conditions that are placed in a WHERE Clause and conditions that resists within the HAVING Clause. In the old version it was not possible to create such statements. After the current patch it’s possible.

In order to use conditions within the WHERE and within the HAVING Clause, the ICondition owns a property named "ConditionClause". This property can be used to specify wheather a condition is placed into the WHERE or the HAVING Clause. A ConditionList ( and that is new ) is defined as "Undefined" which means, that it can have childs that are placed in the WHERE or in the HAVING Clause.  Using this trick allows you to pass the Select Method of the ObjectMapper .NET a ConditionList with child conditions that are set into the WHERE or in the HAVING Clause.

Furthermore a bug has been fixed that lead to wrong SQLs when trying to place a SubSelect into a Condition that queried a Projection Class of the same type as the SubSelect. In that case, the subselect used the aggregation methods of the surrounding Projection class. That bug has been fixed. The SubSelect does now ignore the surrounding projection class as you would expect.

For a better integration the INativePersister interface has been extended for creating and managing IDbCommand objects.

Furthermore a new functionality has been added to enrich an existing handwritten SQL with Server Side Paging informations. This feature is still under development and does not work with all persisters. But there’s more to come.

Wish you happy coding.
- Gerhard


Posted in Releases | No Comments »

News: LinQ to SQL is dead?

Posted by Gerhard Stephan on November 3rd, 2008

Today my collegue showed me an article about LinQ to SQL which says, that Microsoft is not longer working on LinQ to SQL, because Microsoft favourites their own Entitiy Framework. But that Framework earned a lot of critic by many developers and did not released until now …

So there is my appeal for all who are still waiting for a solution of Microsoft: "Don’t wait anymore!" There’re already O/R Mapping Frameworks for .NET that are proved in real world scenarios – like the ObjectMapper .NET. Use it and don’t spend your time on a dead technology.

Cheers
- Gerhard

http://www.infoq.com/news/2008/11/DLINQ-Future


Posted in Uncategorized | No Comments »

New Release – AdFactum ObjectMapper .NET 2.3.3013.0

Posted by Gerhard Stephan on July 13th, 2008

This release covers a lot of smaller and bigger bug fixes for the Microsoft SQL Server 2000 and 2005.

Some Statements could not be executed for the Microsoft SQL Server 2000 by the SqlFile class, because the SQLs that have been executed all ends with a semicolon. Microsoft SQL Server 2005 doesn’t care about, but Microsoft SQL Server 2000 ends up with a failure. This bug has been fixed by removing the semicolon at the end for all databases but Oracle.

The integration check for Microsoft Access failed when a field had a property length greater than 255. Thus forces the Microsoft Access Persister to use a MEMO field, but the integration check did not care about that and throwed a failure, because the max size of a memo field differed to the max size of an integer value. This bug has been fixed by updating the integration check which now takes care to that issue.

Another bug was that the SqlTracer did not take care of the formatting of SQL Statements for the Microsoft Sql Server. It was not everytime possible to use the trace output as a direct input for SQL queries used by the Microsoft SQL Server. This problem has been fixed by changing the parameter formatting for the Microsoft SQL Server.

Furthermore there had been a failure, if the SQL Tracer outputs SQL Statements which uses a parameter more than one time. As a result the second parameter use haven’t been replaced with the concret value by the SQL Tracer. This bug has also been fixed now.

The fith bug has been fixed for the Microsoft SQL Server 2000. The Microsoft SQL Server 2000 has problems to parse a select statement like SELECT TOP(x). The select statement has been changed so that it fits the needs for the Microsoft SQL Server 2000.

If you find some more bugs, please don’t hesitate to report them into the forum of the ObjectMapper .NET.

Best regards
Gerhard Stephan


Posted in Releases | 1 Comment »

Exception: WrongTypeException

Posted by Gerhard Stephan on April 21st, 2008

The WrongTypeException will always be thrown if your object implements the ICreateObject interface, but does not create the expected object type as the result value.

Here’s an example for this:

    /// <summary>

    /// This class creates the wrong object type and causes the WrongTypeException

    /// </summary>

    public class WrongType : BaseVO, ICreateObject

    {

        private int number;

 

        /// <summary>

        /// Gets or sets the number.

        /// </summary>

        /// <value>The number.</value>

        [PropertyName("IntNumber")]

        public int Number

        {

            get { return number; }

            set { number = value; }

        }

 

        /// <summary>

        /// Creates the new object.

        /// </summary>

        /// <returns></returns>

        public IValueObject CreateNewObject()

        {

            return new NullValue();

        }

    }


Posted in Exceptions | No Comments »

Exception: TransactionAlreadyOpenException

Posted by Gerhard Stephan on April 21st, 2008

The TransactionAlreadyOpenException will always be thrown if you try to open an already open transaction a second time. In a simple example this exception can be forced with the following code.

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

            {

                try

                {

                    mapper.BeginTransaction();

                    mapper.BeginTransaction(); // Second try causes the exception

                }

                catch(Exception)

                {

                    mapper.Commit();

                    throw;

                }

            }


Posted in Exceptions | No Comments »

Exception: SqlCoreException

Posted by Gerhard Stephan on April 21st, 2008

The SqlCoreException is the Exception you’ll get most times when working with the ObjectMapper .NET. The SqlCoreException wraps the ADO .NET Exceptions and offers a common interface for catching those exceptions.

Due to this, you don’t have to catch OleDBException, SqlException and OracleException. You only have to catch the SqlCoreExceptions. Thus makes it easy to handle database failures in different scenarios.


Posted in Exceptions | No Comments »

Exception: PersisterDoesNotSupportRepositoryException

Posted by Gerhard Stephan on April 17th, 2008

The PersisterDoesNotSupportRepositoryException will be thrown by the XmlPersister if you try to access the Repository of the ObjectMapper class.

The Repository interface is especially designed for use with relational databases and therefore not accessible when using the XmlPersister.

      string file = Directory.GetCurrentDirectory() + "\\XmlTest.xml";

      XmlPersister persister = new XmlPersister("XmlTest", file);

      AdFactum.Data.ObjectMapper xmlMapper = new AdFactum.Data.ObjectMapper(new UniversalFactory(), persister, Transactions.Manual);

 

            IRepository repository = xmlMapper.Repository;

 

 


Posted in Exceptions | No Comments »

Exception: NoOpenTransactionException

Posted by Gerhard Stephan on April 17th, 2008

The NoOpenTransactionException will always be thrown if a Save-Method is called without opening a Transaction first.

        [Test]

        [ExpectedException(typeof(NoOpenTransactionException))]

        public void TestNoOpenTransactionException()

        {

            Buying buying = new Buying(5, "Hotdogs");

 

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

            {

                // A NoOpenTransactionException will be thrown, because no transaction has been opened.

                mapper.Save(buying);

            }

        }

To prevent this exception you have to call the BeginTransaction Method. It’s recommended to use the BeginTransaction of the OBM Helper class in order to handle nested transactions.

                nested = OBM.BeginTransaction(mapper);

                mapper.Save(buying);
 
               OBM.Commit(mapper, nested);

 


Posted in Exceptions | No Comments »

Exception: MissingSetterException

Posted by Gerhard Stephan on April 17th, 2008

The MissingSetterException will be thrown if a value object shall be loaded that has a property without a setter.

    /// <summary>

    /// This is an uncomplete value object that throws a missing setter exception

    /// </summary>

    public class MissingSetter : ValueObject

    {

        private string missing = string.Empty;

 

        public string Missing

        {

            get { return missing; }

        }

    }

The following test will throw the MissingSetterException when trying to load the object.

        [Test]

        [ExpectedException(typeof(MissingSetterException))]

        public void TestMissingSetterException()

        {

            MissingSetter missingSetter = new MissingSetter();

 

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

            {

                // First save

                bool nested = OBM.BeginTransaction(mapper);

                mapper.Save(missingSetter);

                OBM.Commit(mapper, nested);

 

                // The Load throws the MissingSetterException, because the value can’t be set to the object.

                ObjectDumper.Write(mapper.Load(typeof (MissingSetter), missingSetter.Id));

            }

        }


Posted in Exceptions | No Comments »