有一个WinForms应用程序连接到一个电影SQL Server数据库通过实体框架(EF 6)。
我有以下SQL,我试图转换成LINQ查询
SELECT m.title,f.path,f.size FROM movie m, MovieLinkFile mlf, "file" f
WHERE m.id = mlf.movieId AND mlf.fileId = f.id
AND f.path like 'M%'
ORDER BY f.size
返回12345, MPathTo最佳电影2022最佳动作。mkv,1.54 GB, 720p
size = Varchar(max)
数据库中有3个表:
Movies (id, Title, Year, IMDB,etc)
MoviesLinkFiles (id, MovieId, FileId)
Files (id, path, size, etc)
这将允许我选择具有多个以驱动器M开始的文件的电影?
var Movies = context.movies.AsQueryable()
.Where(m => m.files.Count(file => file.path.StartsWith("M:\")) > 1)
.OrderBy(movie => movie.title);
如何用c#编写LINQ语句
file.path.StartsWith("M:\")
和
OrderBy (file.size)?
在这个例子中,我不需要计算文件数
My attempt errors
var Movies = context.movies.AsQueryable()
.Where(m => m.files.Any(file => file.path.StartsWith("M:\")))
.OrderBy(movie => movie.files.Any(f => f.size) );
错误CS1662无法将lambda表达式转换为预期的委托类型,因为块中的某些返回类型不能隐式转换为委托返回类型
我想你在找这样的东西:
var result = (from movie in context.Movies
join movielink in context.MoviesLinkFiles
on movie.id equals movielink.MovieId
join file in context.Files
on file.id equals movielink.FileId
where path.StartWith("M:\")
orderby file.size asscending
select new { movie.Title, movie.Year, movie.Imbd, file.path, file.size }).ToList();