【发布时间】:2018-12-27 11:49:16
【问题描述】:
我有 InfoAppointment 类,并且该类的表中有 Boat 类的外键 Boat_Id。我想显示包含特定船的 InfoApontamento 类的所有记录。我将如何使用 infoAppointment 表中的船类的外键来查找特定的船,使用 lambda 表达式和存储库?它是一对多的关系
public class InfoAppointment : Entity
{
public string Status { get; set; }
public string Code{ get; set; }
public string Observation{ get; set; }
public virtual Boat Boat { get; set; }
}
public class Boat : Entity
{
public Guid BoatId { get; set; }
public virtual InfoAppointment InfoAppointment { get; set; }
}
我的示例存储库
public virtual IEnumerable<TEntity> Search(Expression<Func<TEntity, bool>> predicate)
{
return Dbset.Where(predicate);
}
public class InfoAppointment Repository : Repository<InfoAppointment >, IInfoAppointmentRepository
{
public InfoAppointmentRepository(RveContext rveContext) : base(rveContext)
{
}
public InfoAppointment GetBoatByName(string boatName)
{
// HOW TO GET THE BOATS USING THE FK
}
public InfoAppointment GetByCode(string code)
{
return Search(c => c.active && !c.excluded && c.Code== code).FirstOrDefault();
}
}
【问题讨论】:
-
name参数是什么?它应该是InfoAppointment还是Boat的属性? (我在任何课程中都没有看到这样的属性) -
@Miamy 该参数来自下拉列表。 This dropdown will have a list of boats, when selecting one, this method receives that name and would look for if that boat is in some registry of the InfoAppointment class.不知道我的想法对不对
-
所以
name是船名,对吗? -
@Miamy 是的!我将进行编辑以使其更清晰
标签: c# asp.net-mvc entity-framework lambda repository-pattern