我正在使用EntityFramework开发Web API。 EntityFramework被构建为一个单独的项目。在API中,我具有以下模型:
namespace Web_API.Models
{
[Table("SomeFiles")]
public class SomeFilesViewModel
{
[Key]
public int FileId { get; set; }
public int PatchNumber{ get; set; }
public string Name { get; set; }
public string Type { get; set; }
}
}
在EF中,我有以下实体:
namespace SomeDataAccess
{
public partial class Patch
{
public int PatchID { get; set; }
public double Number { get; set; }
}
public partial class PatchFile
{
public int FileID { get; set; }
public int PatchID{ get; set; }
public string Name { get; set; }
public string Type { get; set; }
}
}
如何使用LINQ实现GET方法以返回两个Patch
数字(不是补丁ID)之间的文件列表?以下是到目前为止的内容,但是即使加入了“ Number”,也没有将其列为文件的属性。
public async Task<IHttpActionResult> GetSomeFileViewModels(double StartingPatch, double EndingPatch)
{
var files = from pf in _context.PatchFiles
join p in _context.Patches on pf.PatchID equals p.PatchID
select pf;
var patchFiles = await files.Where(i => i.Number(???) >= StartingPatch & i.Number <= EndingPatch)
.Select(someFiles => new SomeFileViewModel
{
FileId = files.FileID,
PatchNumber = (???),
Name = files.Name,
Type = files.Type,
}).ToListAsync();
return !patchFiles.Any()
? (IHttpActionResult)NotFound()
: Ok(patchFiles);
}
答案 0 :(得分:1)
您需要修正您的(Q\.\W*\d{1,2}\W*Incontournable)([^(Q\.)]*)
语句。当前,您刚刚检索了Select
的{{1}}。您可以使用以下选择语句来选择匿名类型:
pf
您现在查询的应该是这样的:
PatchFiles
然后您可以:
select new { PatchFile = pf, Patch = p};