DbFunction call

Posts   
 
    
bernhard
User
Posts: 34
Joined: 15-Jan-2007
# Posted on: 19-Jan-2007 09:50:35   

I want to comare the column of a table and find all recors which are equal ignoring the case.

I want to create the fields "Col11" and "Col22" so these columns do not exist in the DB. Col11 = Lower(DbTableFields.Value); Col22 = Lower(DbTableFields.Value);

This is my code

    ResultsetFields fields = new ResultsetFields(2);
     fields.DefineField(DbTableFields.Value, 0, "Col11", "tbl1");
     fields.DefineField(DbTableFields.Value, 1, "Col22", "tbl2");

     IRelationPredicateBucket theRelationFilter = new RelationPredicateBucket();

     IEntityField2 field1 = EntityFieldFactory.Create("tbl1", "Col11");
     field1.ObjectAlias = "tbl1";
     field1.SetFieldAlias("Col11");
     field1.ExpressionToApply = new DbFunctionCall("LOWER", new object[] { DbTableFields.Value });

     IEntityField2 field2 = EntityFieldFactory.Create("tbl2", "Col22");
     field2.ObjectAlias = "tbl2";
     field2.SetFieldAlias("Col22");
     field2.ExpressionToApply = new DbFunctionCall("LOWER", new object[] { DbTableFields.Value });

     EntityRelation theDummyrelation = new EntityRelation(field1, field2, RelationType.ManyToMany);

     theRelationFilter.Relations.Add(theDummyrelation, "tbl1", "tbl2",  JoinHint.Inner);
     DataTable theTable = new DataTable();
     theDatabaseAdapter.FetchTypedList(fields, theTable, theRelationFilter, null, null);

When I execute it I get the following exception

A first chance exception of type 'System.NullReferenceException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt. bei SD.LLBLGen.Pro.ORMSupportClasses.EntityField2.get_ContainingObjectName() bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetFieldPersistenceInfo(IEntityField2 field) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.InsertPersistenceInfoObjects(IRelationCollection relations) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.InterpretFilterBucket(IRelationPredicateBucket filterBucket, Boolean& relationsPresent, IPredicateExpression& expressionToPass) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateQueryFromElements(IEntityFields2 fieldCollectionToFetch, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize, IFieldPersistenceInfo[]& persistenceInfo, IRetrievalQuery& selectQuery) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause)

What am I doing wrong? I just can not figure out.

Thanks for yout help

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Jan-2007 10:01:00   

Will you please post the SQL Query that you want to run?

Then we can work it out from there.

bernhard
User
Posts: 34
Joined: 15-Jan-2007
# Posted on: 19-Jan-2007 14:26:05   

I found the problem

When I create a new field with IEntityField2 field1 = EntityFieldFactory.Create("tbl1", "Col11"); then the ContainingObjectName of the field is null. When I then added the field to the ResultsetFields I got the NullReferenceException.

I applied the funtion call on a field of the "ResultsetFields" and then it worked.

Thanks for your help