|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
[Hibernate/Nhibernate]Get last insert id
Come da titolo: ci sarebbe modo di ottenere mediante un session.Get soltanto l'ultimo record inserito riferendomi ad un iD ?
Grazie :
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
Ho trovato questo modo:
Codice:
public T GetByLastInsertId<T>(string entityField, string userInput, string orderByField)
{
using(ISession session = WhatEverSessionManager.OpenSession())
{
T t = session.CreateCriteria(typeOf(T))
.Add(Expression.Eq(entityField, userInput))
.AddOrder(Order.Desc(orderByField))
.SetMaxResults(1).UniqueResult<T>();
return t;
}
}
![]() P.S.: esempio di utilizzo: Codice:
IMiaInterfaccia gestore = new MioDbManager();
MyEntity entity = gestore.GetByLastInsertId<MyEntity>("ColonnaEntità", txtQualcosa.Text, "ID_Entità");
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
Ultima modifica di RaouL_BennetH : 09-06-2009 alle 17:35. |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 11:30.




















