2

I have a string property on a class that I would like mapped to a Substring of another column.

Lets say this is my class:

public class MyClass
{
  public virtual string PartNumber { get; set; }

  public virtual string PartNumberPortion { get; set; }
}

And this is my MappingOverride:

public void Override(AutoMapping<MyClass> mapping)
{
   mapping.Map(x => x.PartNumberPortion, "PartNumber").Formula("SUBSTRING(4,20, PartNumber)");
}

The .Formula() piece doesn't work like I had hoped. Is it possible to map a field to a substring of another field?

FYI, I wouldn't need to do this if I could run this query:

PartNumber.Substring(3).Contains("12345")

Unfortunately, having a Substring in a query results in:

Cannot use subqueries on a criteria without a projection.

shanabus
  • 12,989
  • 6
  • 52
  • 78

1 Answers1

3

I successfully got something like this to work in my solution

public override(AutoMapping<MyClass> mapping) 
{
    mapping.Map(x=>x.PartNumberPortion).Formula("SUBSTRING(PartNumber, 4, 20)");
}
Anthony Shaw
  • 8,146
  • 4
  • 44
  • 62