如何使用 Fluent Nhibernate 映射覆盖将子字符串映射到属性?
我在一个类上有一个字符串属性,我希望将其映射到另一列的子字符串。
可以说这是我的课程:
public class MyClass
{
public virtual string PartNumber { get; set; }
public virtual string PartNumberPortion { get; set; }
}
这是我的 MappingOverride:
public void Override(AutoMapping<MyClass> mapping)
{
mapping.Map(x => x.PartNumberPortion, "PartNumber").Formula("SUBSTRING(4,20, PartNumber)");
}
.Formula() 部分没有像我希望的那样工作。是否可以将一个字段映射到另一个字段的子字符串?
仅供参考,如果我可以运行此查询,我就不需要这样做:
PartNumber.Substring(3).Contains("12345")
不幸的是,查询中包含子字符串会导致:
不能对条件使用子查询 没有投影。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我成功地让这样的东西在我的解决方案中发挥作用
I successfully got something like this to work in my solution