0

We are starting to do a conversion to BL Toolkit but are hitting some issues and not finding answers. One such issue is the inability to get the MapValue attribute on our DTO's properly to map.

Using T4 templates, we generate this (as an example):

[MapField("counterparty_fl")]
[MapValue(true,  'y')]
[MapValue(false, 'n')]
public bool CounterpartyFlag { get; set; } // flag_yn_TY(1)  

Our database is Sybase, and the field counterparty_fl is a char(1) that accepts either 'y' or 'n'.

However, when I look at the SQL generated by the following link query, it is writing [counterparty_fl] = 0. What I need is [counterparty_fl] = 'n'

var results = (from i in facade.InputList
               where (
                   i.UserIdentifier == criteria.UserId &&
                   i.CounterpartyFlag == false &&
                   i.Name == criteria.Name)
               select i);  

Has anyone had better luck with MapValue? Any suggestions?

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
Paul K
  • 103
  • 1
  • 10

1 Answers1

2

This type of mapping is not supported for linq queries. The problem is that CounterpartyFlag field can be mapped to 'y', 'n' values, but 'false' in your expression can't be.

You can use enum for CounterpartyFlag field type:

public enum
{
    [MapValue('y')] Yes,
    [MapValue('n')] No
}

This should work.

Budda
  • 18,015
  • 33
  • 124
  • 206
IT.
  • 859
  • 4
  • 11
  • Thanks, that seems to have gotten us past this hurdle. – Paul K Jan 14 '11 at 23:11
  • I do have a question about this. Using this Insert method: public static int Insert(this Table target, Expression> setter); "CounterpartyFlag = false" works just fine. So, somehow on the insert directly off the table's DTO, the conversion just succeeds. What is the difference, if you could explain? I am curious, and I expect my team-mates will want to know, too. – Paul K Jan 16 '11 at 21:58