标签: linq-to-nhibernate

Linq to Nhibernate - Select 中的调用方法破坏了 IQueryable

我需要IQueryable基于域实体的业务逻辑程序集。由于大量类似实体,我想为此目的使用自动映射器。

作品:

_repository.GetList<AgentDto>()
        .Select(dto => new Agent{Login = dto.Login, Password = dto.Password})
        .Where(...).ToList();
Run Code Online (Sandbox Code Playgroud)

不起作用(我Where之前无法放置(另一个程序集)Select):

_repository.GetList<AgentDto>()
        .Select(dto => ToAgent(dto))
        .Where(...).ToList();

private Agent ToAgent(AgentDto dto)
    {
        return new Agent{Login = dto.Login, Password = dto.Password};
    }
Run Code Online (Sandbox Code Playgroud)

例外:

System.NotSupportedException was caught
  Message=CustomerInfo.Domain.Support.Agent ToAgent(CustomerInfo.DAL.DTO.AgentDto)
  Source=NHibernate
  StackTrace:
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMethodCallExpression(MethodCallExpression expression)
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMemberExpression(MemberExpression expression)
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression expression)
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitExpression(Expression expression)
       at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.Visit(Expression expression, VisitorParameters parameters)
       at NHibernate.Linq.Visitors.QueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel …
Run Code Online (Sandbox Code Playgroud)

nhibernate linq-to-nhibernate

2
推荐指数
1
解决办法
3280
查看次数

我将如何更改 Linq-to-Nhibernate 为特定列生成的 SQL?

为了利用 MariaDB 10 上的全文索引,我需要在 sql 字符串中使用这个新的“MATCH AGAINST”语法。

http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html#function_match

我认为如果仅对于某些列,我可以覆盖 linq-to-nhibernate 以更改它在使用时生成的 sql,那将会非常酷

.Where(x => FullTextIndexedStringProperty.Contains("Some word")).ToList().
Run Code Online (Sandbox Code Playgroud)

谁能给我一些关于如何开始的一般指导?

nhibernate linq-to-nhibernate nhibernate-4

2
推荐指数
1
解决办法
796
查看次数

无法让Linq到NHibernate工作

我正在努力让Linq To NHibernate工作.我引用了NHibernate,NHibernate.Linq和NHibernate.ByteCode.Castle.此外,我在同一文件夹中包含所有其他依赖项.

代码/错误消息:

 Public Function GetProjectsByName(ByVal ProjectName As String) As List(Of Project)

    Return (From x In _session.Linq(Of Project)() Where x.Name.Equals(Project))

 End Function
Run Code Online (Sandbox Code Playgroud)

"Linq不是NHibernate.ISession的成员"

...告诉我没有加载LINQ扩展.使用NHibernate.Linq似乎是以一种非常容易使用的方式制作的,因此没有关于如何设置它的教程.(或者至少我找不到任何东西).

你有什么想法,我可能会缺少什么?

更新: 数据访问层的参考

替代文字http://i47.tinypic.com/21jp37r.png

提前致谢

.net vb.net nhibernate linq-to-nhibernate

1
推荐指数
1
解决办法
607
查看次数

带有OR语句的Linq.NHibernate问题

注意:所有代码都写在我的脑海中.它可能包含一些错误.只是得到这个问题的总体意义)

采用这个类定义:(简化为了简化)

public class CodedValue
{
  public string Code { get; set; }
  public string Value {get; set; }
}
Run Code Online (Sandbox Code Playgroud)

拍摄对象:

CodedValue cv1 = new CodedValue(){ Code = "A",  Value = "1" };
CodedValue cv2 = new CodedValue(){ Code = "B",  Value = "2" };
IList<CodedValue> cvList = new List<CodedValue>();
cvList.Add(cv1);
cvList.Add(cv2);
Run Code Online (Sandbox Code Playgroud)

cvList包含要过滤的CodedValue列表.

让我假装我的数据库包含记录:

CODE     VALUE
A        1
A        2
B        1
B        2
Run Code Online (Sandbox Code Playgroud)

现在,我想检索编码值在列表中的所有对象

var filter = from o in MyRepository.List()
             where cvList.Contains(o.CodedValue)
             select o;
Run Code Online (Sandbox Code Playgroud)

NHibernate将此Linq翻译为:

select [Fields...] from …
Run Code Online (Sandbox Code Playgroud)

linq nhibernate linq-to-nhibernate

1
推荐指数
1
解决办法
809
查看次数

linq搜索子集合中的匹配项

我正在寻找一种方法来对linq中的子集合进行IN子句查询.

我有一个例子如下:

Entity: Product.CategoryAssignments - this is an IList<Category> that the product is assigned to. Product can be assigned to multiple categories.
Run Code Online (Sandbox Code Playgroud)

我想检索在类别列表中匹配的所有产品,即

IList<Category> selectedCategories = GetUsersSelectedCategories();
Run Code Online (Sandbox Code Playgroud)

//怎么做的事情

IList<Products> products = from p in repository where p.CategoryAssignments.Contains(?) select p;
Run Code Online (Sandbox Code Playgroud)

任何提示赞赏?

linq linq-to-objects linq-to-nhibernate

1
推荐指数
1
解决办法
1822
查看次数

Nhibernate Linq查询QueryOver

我有以下代码:

1: ids = GetAnArrayOfIds();

2: jobEntities = jobEntities.Where(j => j.Locations.Select(l => l.Id).Any(ids.Contains));
Run Code Online (Sandbox Code Playgroud)

如何使用QueryOver编写2?

谢谢,

nhibernate linq-to-nhibernate queryover

1
推荐指数
1
解决办法
2231
查看次数

NHibernate LINQ 添加查询提示

我正在尝试将“OPTION(RECOMPILE)”添加到我的一些 NHibernate 查询的末尾。我找到了以下帖子:

https://www.codewrecks.com/post/old/2011/07/use-sql-server-query-hints-with-nhibernate-hql-and-icriteria/

这描述了如何添加拦截器来附加 SQL。然而,他们使用 ICriteria,而我使用 LINQ 来查询我的数据。理想情况下,我希望能够这样说:

var query = session.Query<Foo>().OptionRecompile().ToList();
Run Code Online (Sandbox Code Playgroud)

我想知道是否可以向 IQueryable 添加一个扩展方法,它将在查询中注入一些字符串,然后我可以在拦截器中检测到该字符串。这与上面文章中使用的方法类似,他们添加评论并进行检测。

了解更多信息。我之前处理过 LINQ 扩展,并且我知道您可以使用 HQL 生成器添加扩展属性/方法。但根据我的理解,这只能让我说:

var query = session.Query<Foo>().Where(f => f.Bar.OptionRecompile()).ToList();
Run Code Online (Sandbox Code Playgroud)

这并不理想,而且看起来更像是一种黑客行为。如果有人可以提供帮助,我将不胜感激。谢谢

linq nhibernate linq-to-nhibernate

1
推荐指数
1
解决办法
2824
查看次数

将HQL转换为Linq-to-NHibernate的问题

如何转换这个NHibernate HQL(工程)......

static IList<Phone> PhoneList()
{
    ISession session = OpenSession();

    IQuery query = session.CreateQuery("from Phone p where p.Kontact.ContactName = :_contact_name");
    query.SetParameter("_contact_name", "lennon");

    IList<Phone> contacts = query.List<Phone>();

    return contacts;        
}
Run Code Online (Sandbox Code Playgroud)

...到Linq-to-NHibernate(不工作):

static IList<Phone> PhoneListUsingLinq()
{
    string contactName = "lennon";

    ISession session = OpenSession();

    var contacts = from Phone p in session.Query<Phone>()
        where p.Kontact.ContactName == contactName
        select p;

    return contacts.ToList();

}
Run Code Online (Sandbox Code Playgroud)

对象:

public class Contact
{
    public virtual int ContactId { get; set; }
    public virtual string ContactName { get; set; } …
Run Code Online (Sandbox Code Playgroud)

c# nhibernate linq-to-nhibernate nhibernate-3

0
推荐指数
1
解决办法
731
查看次数

Linq Nhibernate离开了加入

盗窃有动作属性

这是我试图让NHibernate.Linq生成的查询:

SELECT * FROM `thefts`
LEFT JOIN memberThefts
ON thefts.id = memberThefts.theftId AND memberThefts.memberId = 1
Run Code Online (Sandbox Code Playgroud)

我想获取所有盗窃的列表,其中action.memberId ==某个数字或者如果它没有找到一行则只是null,简单的查询但它一整天给我一个噩梦!

        thefts = session.Query<Theft>()
            .Fetch(x => x.action)
            .Where(x => x.action.memberId == member.id)
            .ToList();
Run Code Online (Sandbox Code Playgroud)

这将执行以下SQL:

select theft0_.id                 as id9_0_,
       memberthef1_.memberId      as memberId7_1_,
       theft0_.name               as name9_0_,
       theft0_.chance             as chance9_0_,
       memberthef1_.theftId       as theftId7_1_,
       memberthef1_.availableTime as availabl3_7_1_
from   thefts theft0_
       left outer join memberThefts memberthef1_
         on theft0_.id = memberthef1_.theftId,
       memberThefts memberthef2_
where  theft0_.id = memberthef2_.theftId
       and memberthef2_.memberId =1 /* ?p0 */
Run Code Online (Sandbox Code Playgroud)

盗窃类:

    public class …
Run Code Online (Sandbox Code Playgroud)

linq nhibernate fluent-nhibernate linq-to-nhibernate

0
推荐指数
1
解决办法
8911
查看次数