English 中文(简体)
Linq 前往NHibernate,没有获得适当的数据。
原标题:Linq to NHibernate does not return proper data

我有一个班级

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)

最佳回答

它看起来像老的吉卜林克供应商的ug。

它与NHibernate 3公司合作。

问题回答

我认为,你需要规划工作,而不是具体项目类别,以便适当开展这项工作。

您可以尝试的事项:

  • public class ItemMap : ClassMap<Item>
    

    用途

    public class ItemMap : ClassMap<IItem>
    
  • 归还的物体:

    var q = from i in session.Linq<Item>()
            where i.IsActive == true
            select (IItem)i;
    

我不认为你需要担心对具体类型的质疑,即罚款。 仅凭贵存放方法返回接口。 是否有意义?

public IItem GetItem(int id)
{

  var item = from i in session.Linq<Item>()
                where i.IsActive == true
                select i;

  return item;

}

这将使你能够问一下它应该开展的工作,让所有依赖的密码与接口打交道,因为你确实需要接口。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签