C#:您的过滤器和订购LINQ查询如何

发布于 2025-01-30 11:10:27 字数 1219 浏览 3 评论 0原文

通过Entity Framework(EF 6)将Winforms应用程序连接到电影SQL Server数据库。

我有以下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,m \ pathto \最佳电影2022 \ best move.mkv,1.54 GB,720p

varchar(max)类型

尺寸是数据库中的

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)?

在此示例中,我不需要计算文件

错误错误

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表达式转换为预期的委托类型,因为块中的某些返回类型不是隐式转换到委托返回类型

have a WinForms application connected to a Movies SQL Server database via Entity Framework (EF 6).

I have the following SQL which I'm attempting to convert into a LINQ query

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

returns

12345, M\PathTo\Best movie 2022\Best move.mkv,1.54 GB, 720p

size is type Varchar(max)

In the database there are 3 tables:

Movies (id, Title, Year, IMDB,etc)
MoviesLinkFiles (id, MovieId, FileId)
Files (id, path, size, etc)

This will allow me to select the movies that have more than one file starting with drive M?

var Movies = context.movies.AsQueryable()
    .Where(m => m.files.Count(file => file.path.StartsWith("M:\\")) > 1)
    .OrderBy(movie => movie.title);

How do I write the LINQ statement in C# so

file.path.StartsWith("M:\\")

AND

OrderBy (file.size)?

In this example I don't need to count files

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) );

Error CS1662 Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜吻♂芭芘 2025-02-06 11:10:27

我认为您正在寻找这样的东西:

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();

I think that you looking for something like this:

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文