#C Razor Join Data LINQ
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
add a comment |
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
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 aint
field andRating.ID
is alsoInt
– Matt Leyland
Nov 23 '18 at 10:51
add a comment |
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
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
c# visual-studio razor
asked Nov 23 '18 at 10:11
Matt Leyland
6062612
6062612
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 aint
field andRating.ID
is alsoInt
– Matt Leyland
Nov 23 '18 at 10:51
add a comment |
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 aint
field andRating.ID
is alsoInt
– 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
add a comment |
1 Answer
1
active
oldest
votes
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();
Hi, I've just been trying to get anything working using snippets from the net. I have the followingpublic List<Movie> Movie { get;set; }
then using your code when I changed up a littlevar 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 dovar Movies = await ...
and thenreturn 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
Hi, I've just been trying to get anything working using snippets from the net. I have the followingpublic List<Movie> Movie { get;set; }
then using your code when I changed up a littlevar 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 dovar Movies = await ...
and thenreturn 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
add a comment |
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();
Hi, I've just been trying to get anything working using snippets from the net. I have the followingpublic List<Movie> Movie { get;set; }
then using your code when I changed up a littlevar 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 dovar Movies = await ...
and thenreturn 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
add a comment |
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();
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();
edited Nov 23 '18 at 18:16
answered Nov 23 '18 at 18:03
deherch
52537
52537
Hi, I've just been trying to get anything working using snippets from the net. I have the followingpublic List<Movie> Movie { get;set; }
then using your code when I changed up a littlevar 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 dovar Movies = await ...
and thenreturn 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
add a comment |
Hi, I've just been trying to get anything working using snippets from the net. I have the followingpublic List<Movie> Movie { get;set; }
then using your code when I changed up a littlevar 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 dovar Movies = await ...
and thenreturn 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
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 aint
field andRating.ID
is alsoInt
– Matt Leyland
Nov 23 '18 at 10:51