我有一個表有兩個布爾列:isActive和isAcceptingParticipants。如何查找在asp.net中具有特定布爾列值true的SQL數據庫中的所有行?
我想獲得所有這些行都是真的。
我已經在下面包含模型文件和我想要的服務的部分實現。
using System;
using System.ComponentModel.DataAnnotations;
namespace ProjectTracker.Models
{
public class Project
{
[Key]
public int Id { get; set; }
public int CountParticipants { get; set; }
public int CountActiveParticipants { get; set; }
public Boolean isActive { get; set; }
public Boolean isAcceptingParticipants { get; set; }
public int WhoseTurn { get; set; }
}
}
這就是我想要實現GetInProgress這將返回有isActive和isAccepting參與者均爲真正的全行服務模塊。
using ProjectTracker.Models;
using System.Collections.Generic;
using System;
using ProjectTracker.Data;
using System.Linq;
namespace ProjectTracker.Services
{
public interface IProjectData
{
IEnumerable<Project> GetAcceptingParticipants();
IEnumerable<Project> GetInProgress();
Project ParticipatingIn(int id); //Pass userId to this, returns the project that the user is part of
Project Add(Project newProject);
Project Get(int id);
void Delete(int id);
void Commit();
}
public class SqlProjectData : IProjectData
{
private ApplicationDbContext _context;
public SqlProjectData(ApplicationDbContext context)
{
_context = context;
}
public Project Add(Project newProject)
{
_context.Add(newProject);
Commit();
return newProject;
}
public void Commit()
{
_context.SaveChanges();
}
public void Delete(int id)
{
var toBeDeleted = Get(id);
if (toBeDeleted == null) return;
_context.Remove<Project>(toBeDeleted);
}
public Project Get(int id)
{
return _context.Project.FirstOrDefault(r => r.Id == id);
}
public IEnumerable<Project> GetAcceptingParticipants()
{
throw new NotImplementedException();
}
public IEnumerable<Project> GetInProgress()
{
throw new NotImplementedException();
}
public Project ParticipatingIn(int id)
{
throw new NotImplementedException();
}
}
}
需要.ToList()添加爲方法的返回可枚舉 – ISHIDA
@ISHIDA哦,不,他的方法返回一個IEnumerable的''所以你不要不需要那個。 –
Tvde1
這就是我正在尋找的,TY! – islingrad