本文整理汇总了C#中ISession.QueryOver方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.QueryOver方法的具体用法?C# ISession.QueryOver怎么用?C# ISession.QueryOver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.QueryOver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitMembers
public void InitMembers(ISession session)
{
this.Items = session.QueryOver<PollItem>()
.Where(x => x.Poll.Id == this.Id)
.List();
// Objects
this.Objects = session.QueryOver<Poll>()
.Where(p => p.Id != this.Id)
.List();
// Anonymous Users
IList<Employee> users = session.QueryOver<Employee>()
.List();
if (this.AnonymousUser_id.GetValueOrDefault() > 0)
{
foreach (Employee user in users)
{
if (user.Id == 0)
{
user.Id = this.AnonymousUser_id.GetValueOrDefault();
}
}
}
this.AnonymousUsers = users;
}
示例2: InitMembers
public void InitMembers(ISession session)
{
JobTitles = session.QueryOver<JobTitle>()
.OrderBy(x => x.Name).Asc
.List()
.Select(x => new SelectListItem()
{
Text = x.Name,
Value = x.Id.ToString()
});
Departments = session.QueryOver<Department>()
.OrderBy(x => x.Name).Asc
.List()
.Select(x => new SelectListItem()
{
Text = x.Name,
Value = x.Id.ToString()
});
Employees = session.QueryOver<Employee>()
.Where(x => x.IsActive)
.OrderBy(x => x.FirstName).Asc
.OrderBy(x => x.LastName).Asc
.List()
.Select(x => new SelectListItem()
{
Text = x.FullName,
Value = x.Id.ToString()
});
if (!string.IsNullOrEmpty(JobTitle))
JobTitleId = JobTitle.Split(',').Select(x => long.Parse(x)).ToArray();
if (!string.IsNullOrEmpty(Department))
DepartmentId = Department.Split(',').Select(x => long.Parse(x)).ToArray();
if (!string.IsNullOrEmpty(Employee))
EmployeeId = Employee.Split(',').Select(x => long.Parse(x)).ToArray();
}
示例3: CustomersQuery
private IQueryOver<Customer, Customer> CustomersQuery(ISession session, string searchString)
{
var criteria = Restrictions.Or(Restrictions
.On<Customer>(c => c.AccountNumber).IsLike(searchString, MatchMode.Start), Restrictions
.On<Customer>(c => c.CompanyName).IsLike(searchString, MatchMode.Start));
return session.QueryOver<Customer>()
.Where(criteria);
}
示例4: GetBookByISBN
static Book GetBookByISBN(
string ISBN,
ISession session)
{
var query = session.QueryOver<Book>()
.Where(b => b.ISBN == ISBN);
return query.SingleOrDefault();
}
示例5: HandleMessage
public void HandleMessage(ISession session, string message, Action<string> sendAction, ref bool commitTransaction)
{
var msg = JsonConvert.DeserializeObject<LoginMessage>(message);
commitTransaction = true;
if (msg != null) {
var player = session.QueryOver<Player>().Where(x => x.Name == msg.Username && x.Password == msg.Password).SingleOrDefault();
if (player == null) {
sendAction(JsonConvert.SerializeObject(new ResponseMessage {
Success = false,
Error = "Incorrect Username or Password"
}));
return;
}
var loggedInUser = session.QueryOver<LoggedInUser>().Where(x => x.Player.Id == player.Id).SingleOrDefault();
if (loggedInUser != null) {
sendAction(JsonConvert.SerializeObject(new ResponseMessage {
Success = false,
Error = "Already logged in"
}));
return;
}
loggedInUser = new LoggedInUser {
Player = player,
Token = Guid.NewGuid().ToString(),
Expiration = DateTime.UtcNow.AddMinutes(10),
LastAction = null
};
session.Save(loggedInUser);
sendAction(JsonConvert.SerializeObject(new ResponseMessage {
Success = true,
Token = loggedInUser.Token
}));
} else {
sendAction(JsonConvert.SerializeObject(new ResponseMessage {
Success = false,
Error = "Incorrect message."
}));
}
}
示例6: ViolatesTripConstraint
private static bool ViolatesTripConstraint(ISession session, string staffCode, string tripNumber, int id)
{
var trip = session.QueryOver<Trip>().Where(t => t.Observer.StaffCode == staffCode && t.TripNumber == tripNumber).SingleOrDefault();
if (null == trip)
{
return false;
}
return id != trip.Id;
}
示例7: GetMoviesDirectedBy
static IList<Movie> GetMoviesDirectedBy(
string directorName,
ISession session)
{
var query = session.QueryOver<Movie>()
.Where(m => m.Director == directorName)
.OrderBy(m => m.UnitPrice).Asc;
return query.List();
}
示例8: FindPlayer
private static Player FindPlayer(ISession session, int sourceReference)
{
var players = session.QueryOver<Player>().Where(p => p.SourceReference == sourceReference).List();
if (players == null || players.Count > 1)
return null;
return players.Count == 1 ? players[0] : null;
}
示例9: FindCreateClubBySourceId
//TODO - Refactor these into Repository classes if they will be used anywhere else
private static Club FindCreateClubBySourceId(ISession session, PlayerClubDto clubDto)
{
var clubs = session.QueryOver<Club>().Where(p => p.SourceId == clubDto.ClubSourceId).List();
if (clubs == null || clubs.Count > 1)
return null;
return clubs.Count == 1 ? clubs[0] : new Club(clubDto.ClubSourceId, clubDto.ClubCompactName);
}
示例10: Run
protected override void Run(ISession session)
{
var indicadoresHabilitados = session.QueryOver<Indicador>()
.Where(x => x.Habilitado)
.Fetch(x => x.Objetivos)
.Eager.List();
indicadoresHabilitados.AsParallel().ForAll(indicador =>
{
try
{
if (Log.IsInfoEnabled) Log.InfoFormat("Calculando el indicador '{0}) {1}'", indicador.Id, indicador.Nombre);
var fecha = DateTime.Now;
var denominadorQuery = session.CreateSQLQuery(indicador.DenominadorSql);
if(indicador.DenominadorSql.Contains(":Mes")) denominadorQuery.SetParameter("Mes", fecha.Month);
if(indicador.DenominadorSql.Contains(":Anio")) denominadorQuery.SetParameter("Anio", fecha.Year);
var denominador = denominadorQuery.UniqueResult<int>();
if (Log.IsDebugEnabled) Log.DebugFormat("Calculando denominador para el indicador '{0}) {1}': {2}", indicador.Id, indicador.Nombre, denominador);
var numeradorQuery = session.CreateSQLQuery(indicador.NumeradorSql);
if(indicador.NumeradorSql.Contains(":Mes")) numeradorQuery.SetParameter("Mes", fecha.Month);
if(indicador.NumeradorSql.Contains(":Anio")) numeradorQuery.SetParameter("Anio", fecha.Year);
var numerador = numeradorQuery.UniqueResult<int>();
if (Log.IsDebugEnabled) Log.DebugFormat("Calculando numerador para el indicador '{0}) {1}': {2}", indicador.Id, indicador.Nombre, numerador);
var valor = Convert.ToDecimal(numerador / denominador);
var objetivo = indicador.Objetivos.SingleOrDefault(o => o.Anio == fecha.Year && o.Mes == fecha.Month);
if (objetivo == null)
{
objetivo = new ObjetivoIndicador
{
Anio = fecha.Year,
Mes = fecha.Month,
ValorMaximo = valor,
ValorMinimo = valor,
Indicador = indicador
};
indicador.AgregarObjetivo(objetivo);
}
objetivo.FechaLectura = fecha;
objetivo.Valor = valor;
session.Save(objetivo);
if (Log.IsInfoEnabled) Log.InfoFormat("Indicador '{0}) {1}' calculado con valor: {2}", indicador.Id, indicador.Nombre, valor);
}
catch (Exception ex)
{
Log.ErrorFormat("Hubo un error al calcular el indicador '{0}) {1}'. Exc: {2}", indicador.Id, indicador.Nombre, ex);
}
});
}
示例11: GetErrorPageOptions
public virtual List<SelectListItem> GetErrorPageOptions(ISession session, int pageId)
{
var list = session.QueryOver<Webpage>().Where(webpage => webpage.Parent == null).Cacheable().List();
return
list.Where(page => page.Published)
.BuildSelectItemList(
page => page.Name,
page => page.Id.ToString(CultureInfo.InvariantCulture),
page => page.Id == pageId, (string)null);
}
示例12: GetMoviesWith
static IList<Movie> GetMoviesWith(
string actorName,
ISession session)
{
var query = session.QueryOver<Movie>()
.OrderBy(m => m.UnitPrice).Asc
.Inner.JoinQueryOver<ActorRole>(m => m.Actors)
.Where(a => a.Actor == actorName);
return query.List<Movie>();
}
示例13: GetLayoutOptions
public virtual List<SelectListItem> GetLayoutOptions(ISession session, int? selectedLayoutId)
{
return session.QueryOver<Layout>()
.Cacheable()
.List()
.BuildSelectItemList(
layout => layout.Name,
layout => layout.Id.ToString(CultureInfo.InvariantCulture),
layout => layout.Id == selectedLayoutId,
emptyItem: null);
}
示例14: GetMoviePriceList
static IEnumerable<NameAndPrice> GetMoviePriceList(ISession session)
{
return session.QueryOver<Movie>()
.Select(m => m.Name, m => m.UnitPrice)
.List<object[]>()
.Select(props =>
new NameAndPrice()
{
Name = (string) props[0],
Price = (decimal) props[1]
});
}
示例15: GetMediaCategoryOptions
public virtual List<SelectListItem> GetMediaCategoryOptions(ISession session, int? categoryId)
{
var list =
session.QueryOver<MediaCategory>()
.Where(category => category.Parent == null && !category.HideInAdminNav)
.Cacheable()
.List();
return
list.BuildSelectItemList(
category => category.Name,
category => category.Id.ToString(CultureInfo.InvariantCulture),
category => category.Id == categoryId, (string)null);
}