How can I Map a substring to a property with a Fluent Nhibernate Mapping Override?
I have a string property on a class that I would like mapped to a Substring o开发者_运维百科f 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.
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)");
}
精彩评论