The whole confusion in just one place
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using NHibernate;
using NHibernate.Linq;
public class Repository<TEntity> : IRepository<TEntity> where TEntity :
class
{
private readonly ISessionFactory sessionFactory;
public Repository(ISessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
}
protected ISession Session
{
get { return sessionFactory.GetCurrentSession(); }
}
public virtual void Add(TEntity item)
{
Session.Persist(item);
}
public virtual bool Remove(TEntity item)
{
Session.Delete(item);
return true;
}
public virtual int Count
{
get { return Session.Query<TEntity>().Count(); }
}
public virtual bool IsReadOnly
{
get { return false; }
}
#region Implementation of IQueryable
public virtual Expression Expression
{
get { return Session.Query<TEntity>().Expression; }
}
public virtual Type ElementType
{
get { return Session.Query<TEntity>().ElementType; }
}
public virtual IQueryProvider Provider
{
get { return Session.Query<TEntity>().Provider; }
}
#endregion
#region Implementation of IEnumerable
public virtual IEnumerator<TEntity> GetEnumerator()
{
return Session.Query<TEntity>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#region Implementation of IRepository<TEntity>
public virtual TEntity this[int id]
{
get { return Session.Get<TEntity>(id); }
}
public virtual TEntity Get(int id)
{
return Session.Get<TEntity>(id);
}
public virtual TEntity GetProxy(int id)
{
return Session.Load<TEntity>(id);
}
public virtual bool Contains(int id)
{
return Get(id) != null;
}
#endregion
}
On Sat, Aug 11, 2012 at 3:50 AM, Alexander I. Zaytsev <
[email protected]> wrote:
> No drawbacks
>
>
> 2012/8/11 Oskar Berggren <[email protected]>
>
>> Is there any obvious drawback to making Query<T> a non-extension method
>> of ISession?
>>
>> /Oskar
>>
>>
>>
>> 2012/8/11 Rory Plaire <[email protected]>
>>
>>> I agree, it is very confusing. Even after using it and knowing the
>>> solution, I see devs getting tripped up by it.
>>>
>>> It's one of the arguments _for_ using an IRepository abstraction around
>>> ISession, in that it reduces this uncertainty and gives direct access to
>>> the IQueryable surface.
>>>
>>> -r
>>>
>>> On Fri, Aug 10, 2012 at 10:33 PM, Alexander I. Zaytsev <
>>> [email protected]> wrote:
>>>
>>>> Hi all,
>>>>
>>>> People often (about 2 times per week) ask following questions on
>>>> StackOverflow
>>>>
>>>> http://stackoverflow.com/q/11907502/259946
>>>> http://stackoverflow.com/q/11852211/259946
>>>>
>>>> And common answer to such type of questions is
>>>>
>>>> *"You are using QueryOver instead of LINQ (Query<T>() extension
>>>> method)"
>>>> *
>>>> So I think we should perform some actions to remove these kind of
>>>> confusions between QueryOver and Linq APIs.
>>>>
>>>> I think it is because Query<> is an extension method and could not be
>>>> easy found if you don't know where it is.
>>>>
>>>> What do you think?
>>>>
>>>> Best Regards, Alex.
>>>
>>>
>>>
>>
>
--
Fabio Maulo