#C Razor Join Data LINQ












0















Attempting to display a table with a join on the Rating
to the ID within the Ratings table. I'm hitting an issue with the join within my statement.



var Movie = from u in _context.Movie
join g in _context.Ratings
on u.Rating equals g.ID
select (a => new List
{
Ratings = u.Rating,
MovieRating = g.MovieRating

});


Movie = await Movie.ToListAsync();


The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.










share|improve this question


















  • 1





    on u.Rating equals g.ID doesn't looks correct to me at all

    – Rahul
    Nov 23 '18 at 10:14











  • what are the types of Movie.Rating and Rating.ID?

    – suraj13k
    Nov 23 '18 at 10:15











  • Also please follow good naming conventions for your properties. Having RatingID in Movie entity is more appropriate than just 'Rating'

    – suraj13k
    Nov 23 '18 at 10:17











  • Movie.Rating is a int field and Rating.ID is also Int

    – Matt Leyland
    Nov 23 '18 at 10:51
















0















Attempting to display a table with a join on the Rating
to the ID within the Ratings table. I'm hitting an issue with the join within my statement.



var Movie = from u in _context.Movie
join g in _context.Ratings
on u.Rating equals g.ID
select (a => new List
{
Ratings = u.Rating,
MovieRating = g.MovieRating

});


Movie = await Movie.ToListAsync();


The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.










share|improve this question


















  • 1





    on u.Rating equals g.ID doesn't looks correct to me at all

    – Rahul
    Nov 23 '18 at 10:14











  • what are the types of Movie.Rating and Rating.ID?

    – suraj13k
    Nov 23 '18 at 10:15











  • Also please follow good naming conventions for your properties. Having RatingID in Movie entity is more appropriate than just 'Rating'

    – suraj13k
    Nov 23 '18 at 10:17











  • Movie.Rating is a int field and Rating.ID is also Int

    – Matt Leyland
    Nov 23 '18 at 10:51














0












0








0








Attempting to display a table with a join on the Rating
to the ID within the Ratings table. I'm hitting an issue with the join within my statement.



var Movie = from u in _context.Movie
join g in _context.Ratings
on u.Rating equals g.ID
select (a => new List
{
Ratings = u.Rating,
MovieRating = g.MovieRating

});


Movie = await Movie.ToListAsync();


The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.










share|improve this question














Attempting to display a table with a join on the Rating
to the ID within the Ratings table. I'm hitting an issue with the join within my statement.



var Movie = from u in _context.Movie
join g in _context.Ratings
on u.Rating equals g.ID
select (a => new List
{
Ratings = u.Rating,
MovieRating = g.MovieRating

});


Movie = await Movie.ToListAsync();


The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.







c# visual-studio razor






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 10:11









Matt LeylandMatt Leyland

6532612




6532612








  • 1





    on u.Rating equals g.ID doesn't looks correct to me at all

    – Rahul
    Nov 23 '18 at 10:14











  • what are the types of Movie.Rating and Rating.ID?

    – suraj13k
    Nov 23 '18 at 10:15











  • Also please follow good naming conventions for your properties. Having RatingID in Movie entity is more appropriate than just 'Rating'

    – suraj13k
    Nov 23 '18 at 10:17











  • Movie.Rating is a int field and Rating.ID is also Int

    – Matt Leyland
    Nov 23 '18 at 10:51














  • 1





    on u.Rating equals g.ID doesn't looks correct to me at all

    – Rahul
    Nov 23 '18 at 10:14











  • what are the types of Movie.Rating and Rating.ID?

    – suraj13k
    Nov 23 '18 at 10:15











  • Also please follow good naming conventions for your properties. Having RatingID in Movie entity is more appropriate than just 'Rating'

    – suraj13k
    Nov 23 '18 at 10:17











  • Movie.Rating is a int field and Rating.ID is also Int

    – Matt Leyland
    Nov 23 '18 at 10:51








1




1





on u.Rating equals g.ID doesn't looks correct to me at all

– Rahul
Nov 23 '18 at 10:14





on u.Rating equals g.ID doesn't looks correct to me at all

– Rahul
Nov 23 '18 at 10:14













what are the types of Movie.Rating and Rating.ID?

– suraj13k
Nov 23 '18 at 10:15





what are the types of Movie.Rating and Rating.ID?

– suraj13k
Nov 23 '18 at 10:15













Also please follow good naming conventions for your properties. Having RatingID in Movie entity is more appropriate than just 'Rating'

– suraj13k
Nov 23 '18 at 10:17





Also please follow good naming conventions for your properties. Having RatingID in Movie entity is more appropriate than just 'Rating'

– suraj13k
Nov 23 '18 at 10:17













Movie.Rating is a int field and Rating.ID is also Int

– Matt Leyland
Nov 23 '18 at 10:51





Movie.Rating is a int field and Rating.ID is also Int

– Matt Leyland
Nov 23 '18 at 10:51












1 Answer
1






active

oldest

votes


















1














You have some weird syntax like (a => new List { ... Not sure where you are going with that.
Do you have a class named List? are you trying to get a List? Why is "a" in there...since it is not referenced anywhere. You also try to change the type of the Movie variable in your code, the var keyword doesn't work that way. On the first line, you assign a IQueryable< T> to it and later on you try to assign a List< T> to it.



try something like this:



var movieQuery = from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
};
var movies = await movieQuery.ToListAsync(); // query will be executed here


The example code above uses an anonymous class as result so movies will be of type List< T> where T is an anonymous class, if you do have a class called List (for some reason) representing a single result item, then use



select new List { ...


instead of



select new { ...


and if you don't wanna split the query / actual list into 2 variables, you can do something like:



var movies = await (from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
}).ToListAsync();





share|improve this answer


























  • Hi, I've just been trying to get anything working using snippets from the net. I have the following public List<Movie> Movie { get;set; } then using your code when I changed up a little var Movie = await (from m in _context.Movie join r in _context.Ratings on m.Rating equals r.ID.ToString() select new { m.Title, r.MovieRating }).ToListAsync() ;

    – Matt Leyland
    Nov 24 '18 at 7:15











  • how do I then reference this within the html page. @foreach (var item in Model.Movie) { <tr> <td> @Html.DisplayFor(modelItem => item.Title)

    – Matt Leyland
    Nov 24 '18 at 7:16













  • well u need to declare @model ClassNameHere at the top of your cshtml file, if you use anonymous class for a model, the easiest way is to use @model dynamic. In your controller you have to pass the model (your list of movies) to the view. so if u only have the movies you can do var Movies = await ... and then return View(Movies) --> since ur model is of type List< T> where T is anonymous class, you would put @model List<dynamic> on top of ur cshtml page and then in the page itself: @foreach(var movie in Model) { <tr><td>@movie.Title</td><td>@movie.MovieRating</td></tr> }

    – deherch
    Nov 26 '18 at 10:28












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444651%2fc-razor-join-data-linq%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You have some weird syntax like (a => new List { ... Not sure where you are going with that.
Do you have a class named List? are you trying to get a List? Why is "a" in there...since it is not referenced anywhere. You also try to change the type of the Movie variable in your code, the var keyword doesn't work that way. On the first line, you assign a IQueryable< T> to it and later on you try to assign a List< T> to it.



try something like this:



var movieQuery = from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
};
var movies = await movieQuery.ToListAsync(); // query will be executed here


The example code above uses an anonymous class as result so movies will be of type List< T> where T is an anonymous class, if you do have a class called List (for some reason) representing a single result item, then use



select new List { ...


instead of



select new { ...


and if you don't wanna split the query / actual list into 2 variables, you can do something like:



var movies = await (from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
}).ToListAsync();





share|improve this answer


























  • Hi, I've just been trying to get anything working using snippets from the net. I have the following public List<Movie> Movie { get;set; } then using your code when I changed up a little var Movie = await (from m in _context.Movie join r in _context.Ratings on m.Rating equals r.ID.ToString() select new { m.Title, r.MovieRating }).ToListAsync() ;

    – Matt Leyland
    Nov 24 '18 at 7:15











  • how do I then reference this within the html page. @foreach (var item in Model.Movie) { <tr> <td> @Html.DisplayFor(modelItem => item.Title)

    – Matt Leyland
    Nov 24 '18 at 7:16













  • well u need to declare @model ClassNameHere at the top of your cshtml file, if you use anonymous class for a model, the easiest way is to use @model dynamic. In your controller you have to pass the model (your list of movies) to the view. so if u only have the movies you can do var Movies = await ... and then return View(Movies) --> since ur model is of type List< T> where T is anonymous class, you would put @model List<dynamic> on top of ur cshtml page and then in the page itself: @foreach(var movie in Model) { <tr><td>@movie.Title</td><td>@movie.MovieRating</td></tr> }

    – deherch
    Nov 26 '18 at 10:28
















1














You have some weird syntax like (a => new List { ... Not sure where you are going with that.
Do you have a class named List? are you trying to get a List? Why is "a" in there...since it is not referenced anywhere. You also try to change the type of the Movie variable in your code, the var keyword doesn't work that way. On the first line, you assign a IQueryable< T> to it and later on you try to assign a List< T> to it.



try something like this:



var movieQuery = from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
};
var movies = await movieQuery.ToListAsync(); // query will be executed here


The example code above uses an anonymous class as result so movies will be of type List< T> where T is an anonymous class, if you do have a class called List (for some reason) representing a single result item, then use



select new List { ...


instead of



select new { ...


and if you don't wanna split the query / actual list into 2 variables, you can do something like:



var movies = await (from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
}).ToListAsync();





share|improve this answer


























  • Hi, I've just been trying to get anything working using snippets from the net. I have the following public List<Movie> Movie { get;set; } then using your code when I changed up a little var Movie = await (from m in _context.Movie join r in _context.Ratings on m.Rating equals r.ID.ToString() select new { m.Title, r.MovieRating }).ToListAsync() ;

    – Matt Leyland
    Nov 24 '18 at 7:15











  • how do I then reference this within the html page. @foreach (var item in Model.Movie) { <tr> <td> @Html.DisplayFor(modelItem => item.Title)

    – Matt Leyland
    Nov 24 '18 at 7:16













  • well u need to declare @model ClassNameHere at the top of your cshtml file, if you use anonymous class for a model, the easiest way is to use @model dynamic. In your controller you have to pass the model (your list of movies) to the view. so if u only have the movies you can do var Movies = await ... and then return View(Movies) --> since ur model is of type List< T> where T is anonymous class, you would put @model List<dynamic> on top of ur cshtml page and then in the page itself: @foreach(var movie in Model) { <tr><td>@movie.Title</td><td>@movie.MovieRating</td></tr> }

    – deherch
    Nov 26 '18 at 10:28














1












1








1







You have some weird syntax like (a => new List { ... Not sure where you are going with that.
Do you have a class named List? are you trying to get a List? Why is "a" in there...since it is not referenced anywhere. You also try to change the type of the Movie variable in your code, the var keyword doesn't work that way. On the first line, you assign a IQueryable< T> to it and later on you try to assign a List< T> to it.



try something like this:



var movieQuery = from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
};
var movies = await movieQuery.ToListAsync(); // query will be executed here


The example code above uses an anonymous class as result so movies will be of type List< T> where T is an anonymous class, if you do have a class called List (for some reason) representing a single result item, then use



select new List { ...


instead of



select new { ...


and if you don't wanna split the query / actual list into 2 variables, you can do something like:



var movies = await (from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
}).ToListAsync();





share|improve this answer















You have some weird syntax like (a => new List { ... Not sure where you are going with that.
Do you have a class named List? are you trying to get a List? Why is "a" in there...since it is not referenced anywhere. You also try to change the type of the Movie variable in your code, the var keyword doesn't work that way. On the first line, you assign a IQueryable< T> to it and later on you try to assign a List< T> to it.



try something like this:



var movieQuery = from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
};
var movies = await movieQuery.ToListAsync(); // query will be executed here


The example code above uses an anonymous class as result so movies will be of type List< T> where T is an anonymous class, if you do have a class called List (for some reason) representing a single result item, then use



select new List { ...


instead of



select new { ...


and if you don't wanna split the query / actual list into 2 variables, you can do something like:



var movies = await (from u in _context.Movie
join g in _context.Ratings on u.Rating equals g.ID
select new
{
Ratings = u.Rating,
MovieRating = g.MovieRating
}).ToListAsync();






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 18:16

























answered Nov 23 '18 at 18:03









deherchdeherch

52337




52337













  • Hi, I've just been trying to get anything working using snippets from the net. I have the following public List<Movie> Movie { get;set; } then using your code when I changed up a little var Movie = await (from m in _context.Movie join r in _context.Ratings on m.Rating equals r.ID.ToString() select new { m.Title, r.MovieRating }).ToListAsync() ;

    – Matt Leyland
    Nov 24 '18 at 7:15











  • how do I then reference this within the html page. @foreach (var item in Model.Movie) { <tr> <td> @Html.DisplayFor(modelItem => item.Title)

    – Matt Leyland
    Nov 24 '18 at 7:16













  • well u need to declare @model ClassNameHere at the top of your cshtml file, if you use anonymous class for a model, the easiest way is to use @model dynamic. In your controller you have to pass the model (your list of movies) to the view. so if u only have the movies you can do var Movies = await ... and then return View(Movies) --> since ur model is of type List< T> where T is anonymous class, you would put @model List<dynamic> on top of ur cshtml page and then in the page itself: @foreach(var movie in Model) { <tr><td>@movie.Title</td><td>@movie.MovieRating</td></tr> }

    – deherch
    Nov 26 '18 at 10:28



















  • Hi, I've just been trying to get anything working using snippets from the net. I have the following public List<Movie> Movie { get;set; } then using your code when I changed up a little var Movie = await (from m in _context.Movie join r in _context.Ratings on m.Rating equals r.ID.ToString() select new { m.Title, r.MovieRating }).ToListAsync() ;

    – Matt Leyland
    Nov 24 '18 at 7:15











  • how do I then reference this within the html page. @foreach (var item in Model.Movie) { <tr> <td> @Html.DisplayFor(modelItem => item.Title)

    – Matt Leyland
    Nov 24 '18 at 7:16













  • well u need to declare @model ClassNameHere at the top of your cshtml file, if you use anonymous class for a model, the easiest way is to use @model dynamic. In your controller you have to pass the model (your list of movies) to the view. so if u only have the movies you can do var Movies = await ... and then return View(Movies) --> since ur model is of type List< T> where T is anonymous class, you would put @model List<dynamic> on top of ur cshtml page and then in the page itself: @foreach(var movie in Model) { <tr><td>@movie.Title</td><td>@movie.MovieRating</td></tr> }

    – deherch
    Nov 26 '18 at 10:28

















Hi, I've just been trying to get anything working using snippets from the net. I have the following public List<Movie> Movie { get;set; } then using your code when I changed up a little var Movie = await (from m in _context.Movie join r in _context.Ratings on m.Rating equals r.ID.ToString() select new { m.Title, r.MovieRating }).ToListAsync() ;

– Matt Leyland
Nov 24 '18 at 7:15





Hi, I've just been trying to get anything working using snippets from the net. I have the following public List<Movie> Movie { get;set; } then using your code when I changed up a little var Movie = await (from m in _context.Movie join r in _context.Ratings on m.Rating equals r.ID.ToString() select new { m.Title, r.MovieRating }).ToListAsync() ;

– Matt Leyland
Nov 24 '18 at 7:15













how do I then reference this within the html page. @foreach (var item in Model.Movie) { <tr> <td> @Html.DisplayFor(modelItem => item.Title)

– Matt Leyland
Nov 24 '18 at 7:16







how do I then reference this within the html page. @foreach (var item in Model.Movie) { <tr> <td> @Html.DisplayFor(modelItem => item.Title)

– Matt Leyland
Nov 24 '18 at 7:16















well u need to declare @model ClassNameHere at the top of your cshtml file, if you use anonymous class for a model, the easiest way is to use @model dynamic. In your controller you have to pass the model (your list of movies) to the view. so if u only have the movies you can do var Movies = await ... and then return View(Movies) --> since ur model is of type List< T> where T is anonymous class, you would put @model List<dynamic> on top of ur cshtml page and then in the page itself: @foreach(var movie in Model) { <tr><td>@movie.Title</td><td>@movie.MovieRating</td></tr> }

– deherch
Nov 26 '18 at 10:28





well u need to declare @model ClassNameHere at the top of your cshtml file, if you use anonymous class for a model, the easiest way is to use @model dynamic. In your controller you have to pass the model (your list of movies) to the view. so if u only have the movies you can do var Movies = await ... and then return View(Movies) --> since ur model is of type List< T> where T is anonymous class, you would put @model List<dynamic> on top of ur cshtml page and then in the page itself: @foreach(var movie in Model) { <tr><td>@movie.Title</td><td>@movie.MovieRating</td></tr> }

– deherch
Nov 26 '18 at 10:28




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444651%2fc-razor-join-data-linq%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini