Differnet Datatype in a predicate

Posts   
 
    
Posts: 8
Joined: 15-Mar-2007
# Posted on: 20-Aug-2007 14:40:32   

How can I create a predicate to compare two columns of different data types. for example an integer versus a string. Is there any way for type casting?

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 20-Aug-2007 17:44:29   

Try using the DBFunctionCall and a sql-conversion-function in your predicate, but I'm not quite sure that would work either, I've found a few post related a bug in 2.0 regarding DBFunctionCall with CONVERT and CAST sql functions (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=6801) and it seems it's been fixed in 2.5 (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10154).

I'll better try a different approach to accomplish this, maybe you could explain a little further the scenario you're in?

Posts: 8
Joined: 15-Mar-2007
# Posted on: 21-Aug-2007 10:09:55   

I would like to join two table on columns with different data types. for example : Column c1 from Table T1 and Column C2 from Table T2. C1 is integer and C2 is string. In SQL Server I write this query : Select * from T1 inner join T2 on Cast(C1 as Nvarchar(20)) = C2

the following statements should produce the same result:

[C#]

customRelation = new EntityRelation(RelationType.OneToOne); customRelation.AddEntityFieldPair(C1Field,C2Field);

but there would be no Cast function in the result, so SQL Server raise the following error :

Syntax error converting the nvarchar value 'ACC' to a column of data type int.

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

customRelation = new EntityRelation(RelationType.OneToOne); customRelation.AddEntityFieldPair(C1Field,C2Field);

Casting is not done automatically for you. You should create a Predicate for the Cast(C1 as Nvarchar(20)) = C2, using a DBFunction call (use v.2.5, ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10154).

Use this Predicate filter for the entityRelation's CustomFilter propertry. And set the CustomFilterReplacesOnClause to true.