开发者

fluent mapping question-give a certain value to a property

Consider following 2 classes:

public class TypeAGood{
  public virtual int Id{get;set;}
  public virtual string Description{get;set;}
  public virtual Type Type{get;set;}  
}

public virtual class Type{
  public virtual int 开发者_StackOverflowId{get;set;}
  public virtual string Name{get;set;}
}

mappings:

 public class TypeMap : ClassMap<Type>
    {
        public TypeMap()
        {
            Table("Type");
            Id(x => x.Id);
            Map(x => x.Name);
        }
    }

 public class TypeAGoodMap : ClassMap<TypeAGood>
 {
        public TypeAGoodMap()
        {
            Table("Good");
            Id(x => x.Id);
            Map(x => x.Description);
            References(x => x.Type)
               .Fetch.Join()
               .Column("TypeId")
               .ForeignKey("Id");
        }
 }

Type could have different values like a,b,c.

How can I change the TypeAGoodMap to only map the goods which have Type a?

Thanks,

Al


Sounds like you're looking for a filter described here. Unfortunately this is not supported in FluentNhibernate yet. But this is what it looks like in hbm:

<filter name="typeAfilter" condition=":typeA = TypeId"/>

and then in the query do something like this:

ISession session = ...;
session.EnableFilter("typeAfilter").SetParameter("typeA ", "a");
IList<TypeAGood> results = session.CreateCriteria(typeof(TypeAGood))
         .List<TypeAGood>();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜