I have table with 10 000 elements.
IQuerable<IEntity> query = dataRep.Get<IEntity>()
.Query();
I need to get the index(rownum) of selected obj
without getting all table items
var obj = query.Where( x => x.Name == "testName")
.FirstOrDefault();
The simple sql work fine :
select name, id, r from
(
select name, id, rownum r from collections order by id
) where name = 'testName';
How do this in Linq to NHibernate ?
Edit:
I tried add to IEntity
class property RowNumber
and mapping this on hbm
as
<property name="RowNumber" formula="rownum" />
But after
var index = query.Where( x => x.Name == "testName")
.Select( x => x.RowNumber)
.FirstOrDefault();
Get always 1
value
Darren
Can you not just filter the query directly?
IQuerable<IEntity> query = dataRep.Get<IEntity>()
.Query()
.FirstOrDefault(x => x.Name == "testName");
Edit:
To get the item you can project into an anonymous type:
var query = (from data in dataRep.Get<IEntity>().Query()
where Name == "testName"
select new
{
id = data.id,
rowNumber = data.rowNumber
}).FirstOrDefault();
来源:https://stackoverflow.com/questions/10226118/get-item-index-rownum