我有一个班级
public class Item : IItem
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual bool IsActive { get; set; }
}
public interface IItem
{
Guid Id { get; set; }
string Name { get; set; }
bool IsActive { get; set; }
}
public class ItemMap : ClassMap<Item>
{
public ItemMap()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.IsActive);
}
}
在我的数据库中,我制作了五个项目。 有3个具有实际旗帜,2个则伪造。
在使用接口时,所有5项物品均归来:
var q = from i in session.Linq<IItem>()
where i.IsActive == true
select i;
然而,在使用具体类别时,它归还了适当的三个项目:
var q = from i in session.Linq<Item>()
where i.IsActive == true
select i;
EDIT
I have would like to return an Interface, because I have read that I should return non-concrete classes. Please note that in actuality, these Linq queries are in a repository in a different project (in case this becomes a web or WPF app)