我的用例是根据发票的ID和发票行号列表获取发票及其行的子集.我想急切地在与发票相同的往返途中获取线路.我假设它是这样做的,但我找不到参数类型的正确类型声明:
域对象:
public class Invoice { public int ID {get;set;} public List<Invoiceline> lines {get;set;}}public class Invoiceline { public int ID {get;set} public int lineNumber {get;set;}}
映射:
public class InvoiceMap : ClassMap<Invoice> { public InvoiceMap() { ID(x => x.ID); HasMany(x => x.lines).ApplyFilter<OnlylinesWithNumbersFilter>(); }}public class InvoicelineMap : ClassMap<Invoiceline> { public InvoicelineMap() { ID(x => x.ID); Map(x => x.lineNumber); }}
过滤器定义:
public class OnlylinesWithNumbersFilter : FilterDeFinition{ public OnlylinesWithNumbersFilter() { Withname("OnlylinesWithNumbers"); WithCondition("lineNumber IN (:lineNumbers)"); AddParameter("lineNumbers",?? What to put here ??); }}
查询:
var filtername = "OnlylinesWithNumbers";session.EnableFilter(filtername).SetParameterList("lineNumbers",new[] {1,2,3});var query = session.queryOver<Invoice>() .Where(i => i.ID == 42) .Fetch(i => i.lines).Eager .transformUsing(new distinctRootEntityResulttransformer());var result = query.SingleOrDefault();session.disableFilter(filtername);解决方法 就拿-2
Invoiceline invoicelineAlias = null;var List = session.queryOver<Invoice>() .Where(x => x.ID == 1) .JoinqueryOver(x => x.lines,() => invoicelineAlias,JoinType.leftOuterJoin) .WhereRestrictionOn(() => invoicelineAlias.lineNumber) .IsIn(new List<int> { 1,3 }) .List();
制作sql:
SELECT this_.ID as ID2_1_,invoicelin1_.Invoice_ID as Invoice3_3_,invoicelin1_.ID as ID3_,invoicelin1_.ID as ID3_0_,invoicelin1_.lineNumber as lineNumber3_0_ FROM "Invoice" this_ left outer join "Invoiceline" invoicelin1_ on this_.ID=invoicelin1_.Invoice_ID WHERE this_.ID = @p0 and invoicelin1_.lineNumber in ( @p1,@p2,@p3 ); @p0 = 1 [Type: Int32 (0)],@p1 = 1 [Type: Int32 (0)],@p2 = 2 [Type: Int32 (0)],@p3 = 3 [Type: Int32 (0)]总结
以上是内存溢出为你收集整理的c# – 带参数化IN子句的FluentNHibernate过滤器全部内容,希望文章能够帮你解决c# – 带参数化IN子句的FluentNHibernate过滤器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)