cannot implicity convert list
up vote
0
down vote
favorite
I want to get the check in status of employees but it is only letting me to return one of them, First
or FirstOrDefault
when i try to convert it to a list it's telling me:
Cannot convert List<> to ..Data.Entities.Checkinout
EmployeeCollection = (from userinfo in context.Userinfo
join department in context.Dept on userinfo.Deptid equals department.Deptid
where id == userinfo.Userid
select new Employee()
{
Name = userinfo.Name,
Department = department.DeptName,
CardNumber = userinfo.CardNum,
Status = userinfo.UserFlag.ToString(),
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
).ToList()
c# entity-framework
|
show 5 more comments
up vote
0
down vote
favorite
I want to get the check in status of employees but it is only letting me to return one of them, First
or FirstOrDefault
when i try to convert it to a list it's telling me:
Cannot convert List<> to ..Data.Entities.Checkinout
EmployeeCollection = (from userinfo in context.Userinfo
join department in context.Dept on userinfo.Deptid equals department.Deptid
where id == userinfo.Userid
select new Employee()
{
Name = userinfo.Name,
Department = department.DeptName,
CardNumber = userinfo.CardNum,
Status = userinfo.UserFlag.ToString(),
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
).ToList()
c# entity-framework
You mean where you assignActualCheckinStatuse
in the object initializer fornew Employee
? What is the declared type ofActualCheckinStatuse
? If you change the.First()
in the above code into.ToList()
will the new typeList<Checkinout>
be something that is compatible with the declared type of the property?
– Jeppe Stig Nielsen
Nov 8 at 9:04
Post the entire message, not just part of the message andso on
. If it's a compilation error, it contains the exact line that caused the error. If it's an exception, it will show what actually happened and the call stack will show where it happened. You can get the entire exception easily withException.ToString()
.
– Panagiotis Kanavos
Nov 8 at 9:35
As for this error, it's pretty clear that you tried to assign an IQueryable<T> to a List property or field. Without the definition of the classes it's impossible to say what's wrong. Post code that actually reproduces the problem.
– Panagiotis Kanavos
Nov 8 at 9:35
@JeppeStigNielsen yes the list is not compatible with the type im trying to display
– Em44
Nov 8 at 13:55
How is EmployeeCollection declared? (what's its type?)
– johey
Nov 8 at 14:01
|
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to get the check in status of employees but it is only letting me to return one of them, First
or FirstOrDefault
when i try to convert it to a list it's telling me:
Cannot convert List<> to ..Data.Entities.Checkinout
EmployeeCollection = (from userinfo in context.Userinfo
join department in context.Dept on userinfo.Deptid equals department.Deptid
where id == userinfo.Userid
select new Employee()
{
Name = userinfo.Name,
Department = department.DeptName,
CardNumber = userinfo.CardNum,
Status = userinfo.UserFlag.ToString(),
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
).ToList()
c# entity-framework
I want to get the check in status of employees but it is only letting me to return one of them, First
or FirstOrDefault
when i try to convert it to a list it's telling me:
Cannot convert List<> to ..Data.Entities.Checkinout
EmployeeCollection = (from userinfo in context.Userinfo
join department in context.Dept on userinfo.Deptid equals department.Deptid
where id == userinfo.Userid
select new Employee()
{
Name = userinfo.Name,
Department = department.DeptName,
CardNumber = userinfo.CardNum,
Status = userinfo.UserFlag.ToString(),
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
).ToList()
c# entity-framework
c# entity-framework
edited Nov 9 at 8:41
Panagiotis Kanavos
52.7k479107
52.7k479107
asked Nov 8 at 8:58
Em44
106
106
You mean where you assignActualCheckinStatuse
in the object initializer fornew Employee
? What is the declared type ofActualCheckinStatuse
? If you change the.First()
in the above code into.ToList()
will the new typeList<Checkinout>
be something that is compatible with the declared type of the property?
– Jeppe Stig Nielsen
Nov 8 at 9:04
Post the entire message, not just part of the message andso on
. If it's a compilation error, it contains the exact line that caused the error. If it's an exception, it will show what actually happened and the call stack will show where it happened. You can get the entire exception easily withException.ToString()
.
– Panagiotis Kanavos
Nov 8 at 9:35
As for this error, it's pretty clear that you tried to assign an IQueryable<T> to a List property or field. Without the definition of the classes it's impossible to say what's wrong. Post code that actually reproduces the problem.
– Panagiotis Kanavos
Nov 8 at 9:35
@JeppeStigNielsen yes the list is not compatible with the type im trying to display
– Em44
Nov 8 at 13:55
How is EmployeeCollection declared? (what's its type?)
– johey
Nov 8 at 14:01
|
show 5 more comments
You mean where you assignActualCheckinStatuse
in the object initializer fornew Employee
? What is the declared type ofActualCheckinStatuse
? If you change the.First()
in the above code into.ToList()
will the new typeList<Checkinout>
be something that is compatible with the declared type of the property?
– Jeppe Stig Nielsen
Nov 8 at 9:04
Post the entire message, not just part of the message andso on
. If it's a compilation error, it contains the exact line that caused the error. If it's an exception, it will show what actually happened and the call stack will show where it happened. You can get the entire exception easily withException.ToString()
.
– Panagiotis Kanavos
Nov 8 at 9:35
As for this error, it's pretty clear that you tried to assign an IQueryable<T> to a List property or field. Without the definition of the classes it's impossible to say what's wrong. Post code that actually reproduces the problem.
– Panagiotis Kanavos
Nov 8 at 9:35
@JeppeStigNielsen yes the list is not compatible with the type im trying to display
– Em44
Nov 8 at 13:55
How is EmployeeCollection declared? (what's its type?)
– johey
Nov 8 at 14:01
You mean where you assign
ActualCheckinStatuse
in the object initializer for new Employee
? What is the declared type of ActualCheckinStatuse
? If you change the .First()
in the above code into .ToList()
will the new type List<Checkinout>
be something that is compatible with the declared type of the property?– Jeppe Stig Nielsen
Nov 8 at 9:04
You mean where you assign
ActualCheckinStatuse
in the object initializer for new Employee
? What is the declared type of ActualCheckinStatuse
? If you change the .First()
in the above code into .ToList()
will the new type List<Checkinout>
be something that is compatible with the declared type of the property?– Jeppe Stig Nielsen
Nov 8 at 9:04
Post the entire message, not just part of the message and
so on
. If it's a compilation error, it contains the exact line that caused the error. If it's an exception, it will show what actually happened and the call stack will show where it happened. You can get the entire exception easily with Exception.ToString()
.– Panagiotis Kanavos
Nov 8 at 9:35
Post the entire message, not just part of the message and
so on
. If it's a compilation error, it contains the exact line that caused the error. If it's an exception, it will show what actually happened and the call stack will show where it happened. You can get the entire exception easily with Exception.ToString()
.– Panagiotis Kanavos
Nov 8 at 9:35
As for this error, it's pretty clear that you tried to assign an IQueryable<T> to a List property or field. Without the definition of the classes it's impossible to say what's wrong. Post code that actually reproduces the problem.
– Panagiotis Kanavos
Nov 8 at 9:35
As for this error, it's pretty clear that you tried to assign an IQueryable<T> to a List property or field. Without the definition of the classes it's impossible to say what's wrong. Post code that actually reproduces the problem.
– Panagiotis Kanavos
Nov 8 at 9:35
@JeppeStigNielsen yes the list is not compatible with the type im trying to display
– Em44
Nov 8 at 13:55
@JeppeStigNielsen yes the list is not compatible with the type im trying to display
– Em44
Nov 8 at 13:55
How is EmployeeCollection declared? (what's its type?)
– johey
Nov 8 at 14:01
How is EmployeeCollection declared? (what's its type?)
– johey
Nov 8 at 14:01
|
show 5 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
A part of your code looks like this:
new Employee()
{
Name = ...,
Department = ...,
CardNumber = ...,
Status = ...,
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
Here, the expression (from checkinout in ... select new Checkinout { ... })
will be an enumeration (or sequence, if you prefer) of Checkinout
instances. When you do .First()
on that, as above, the result will be one instance of type Checkinout
.
As far as I understand, that compiles well. And it is because the property ActualCheckinStatuse
that you assign to in this initializer, has the same declared type, Checkinout
.
If instead after this parenthesis (from checkinout in ... select new Checkinout { ... })
you append .ToList()
, then what you get is all those Checkinout
instances in a .NET List<>
in memory. Sure enough you cannot assign that to ActualCheckinStatuse
because the types are not compatible. One Checkinout
called ActualCheckinStatuse
cannot be set to a whole List<>
of such Checkinout
s.
Do you know how could I display it as a list because if I make the ActualCheckinStatus to a list of Checkinouts I am unable to display it in my View due to another error : .. does not contain a definition for getenumerator
– Em44
Nov 9 at 9:30
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
A part of your code looks like this:
new Employee()
{
Name = ...,
Department = ...,
CardNumber = ...,
Status = ...,
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
Here, the expression (from checkinout in ... select new Checkinout { ... })
will be an enumeration (or sequence, if you prefer) of Checkinout
instances. When you do .First()
on that, as above, the result will be one instance of type Checkinout
.
As far as I understand, that compiles well. And it is because the property ActualCheckinStatuse
that you assign to in this initializer, has the same declared type, Checkinout
.
If instead after this parenthesis (from checkinout in ... select new Checkinout { ... })
you append .ToList()
, then what you get is all those Checkinout
instances in a .NET List<>
in memory. Sure enough you cannot assign that to ActualCheckinStatuse
because the types are not compatible. One Checkinout
called ActualCheckinStatuse
cannot be set to a whole List<>
of such Checkinout
s.
Do you know how could I display it as a list because if I make the ActualCheckinStatus to a list of Checkinouts I am unable to display it in my View due to another error : .. does not contain a definition for getenumerator
– Em44
Nov 9 at 9:30
add a comment |
up vote
0
down vote
A part of your code looks like this:
new Employee()
{
Name = ...,
Department = ...,
CardNumber = ...,
Status = ...,
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
Here, the expression (from checkinout in ... select new Checkinout { ... })
will be an enumeration (or sequence, if you prefer) of Checkinout
instances. When you do .First()
on that, as above, the result will be one instance of type Checkinout
.
As far as I understand, that compiles well. And it is because the property ActualCheckinStatuse
that you assign to in this initializer, has the same declared type, Checkinout
.
If instead after this parenthesis (from checkinout in ... select new Checkinout { ... })
you append .ToList()
, then what you get is all those Checkinout
instances in a .NET List<>
in memory. Sure enough you cannot assign that to ActualCheckinStatuse
because the types are not compatible. One Checkinout
called ActualCheckinStatuse
cannot be set to a whole List<>
of such Checkinout
s.
Do you know how could I display it as a list because if I make the ActualCheckinStatus to a list of Checkinouts I am unable to display it in my View due to another error : .. does not contain a definition for getenumerator
– Em44
Nov 9 at 9:30
add a comment |
up vote
0
down vote
up vote
0
down vote
A part of your code looks like this:
new Employee()
{
Name = ...,
Department = ...,
CardNumber = ...,
Status = ...,
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
Here, the expression (from checkinout in ... select new Checkinout { ... })
will be an enumeration (or sequence, if you prefer) of Checkinout
instances. When you do .First()
on that, as above, the result will be one instance of type Checkinout
.
As far as I understand, that compiles well. And it is because the property ActualCheckinStatuse
that you assign to in this initializer, has the same declared type, Checkinout
.
If instead after this parenthesis (from checkinout in ... select new Checkinout { ... })
you append .ToList()
, then what you get is all those Checkinout
instances in a .NET List<>
in memory. Sure enough you cannot assign that to ActualCheckinStatuse
because the types are not compatible. One Checkinout
called ActualCheckinStatuse
cannot be set to a whole List<>
of such Checkinout
s.
A part of your code looks like this:
new Employee()
{
Name = ...,
Department = ...,
CardNumber = ...,
Status = ...,
ActualCheckinStatuse = (from checkinout in context.Checkinout
join status in context.Status on checkinout.CheckType equals status.Statusid
where checkinout.Userid == userinfo.Userid
orderby checkinout.CheckTime descending
select new Checkinout
{
CheckStatus = status.StatusText,
CheckTime = checkinout.CheckTime
}).First()
}
Here, the expression (from checkinout in ... select new Checkinout { ... })
will be an enumeration (or sequence, if you prefer) of Checkinout
instances. When you do .First()
on that, as above, the result will be one instance of type Checkinout
.
As far as I understand, that compiles well. And it is because the property ActualCheckinStatuse
that you assign to in this initializer, has the same declared type, Checkinout
.
If instead after this parenthesis (from checkinout in ... select new Checkinout { ... })
you append .ToList()
, then what you get is all those Checkinout
instances in a .NET List<>
in memory. Sure enough you cannot assign that to ActualCheckinStatuse
because the types are not compatible. One Checkinout
called ActualCheckinStatuse
cannot be set to a whole List<>
of such Checkinout
s.
answered Nov 9 at 8:40
Jeppe Stig Nielsen
42.6k672130
42.6k672130
Do you know how could I display it as a list because if I make the ActualCheckinStatus to a list of Checkinouts I am unable to display it in my View due to another error : .. does not contain a definition for getenumerator
– Em44
Nov 9 at 9:30
add a comment |
Do you know how could I display it as a list because if I make the ActualCheckinStatus to a list of Checkinouts I am unable to display it in my View due to another error : .. does not contain a definition for getenumerator
– Em44
Nov 9 at 9:30
Do you know how could I display it as a list because if I make the ActualCheckinStatus to a list of Checkinouts I am unable to display it in my View due to another error : .. does not contain a definition for getenumerator
– Em44
Nov 9 at 9:30
Do you know how could I display it as a list because if I make the ActualCheckinStatus to a list of Checkinouts I am unable to display it in my View due to another error : .. does not contain a definition for getenumerator
– Em44
Nov 9 at 9:30
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%2f53204357%2fcannot-implicity-convert-list%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
You mean where you assign
ActualCheckinStatuse
in the object initializer fornew Employee
? What is the declared type ofActualCheckinStatuse
? If you change the.First()
in the above code into.ToList()
will the new typeList<Checkinout>
be something that is compatible with the declared type of the property?– Jeppe Stig Nielsen
Nov 8 at 9:04
Post the entire message, not just part of the message and
so on
. If it's a compilation error, it contains the exact line that caused the error. If it's an exception, it will show what actually happened and the call stack will show where it happened. You can get the entire exception easily withException.ToString()
.– Panagiotis Kanavos
Nov 8 at 9:35
As for this error, it's pretty clear that you tried to assign an IQueryable<T> to a List property or field. Without the definition of the classes it's impossible to say what's wrong. Post code that actually reproduces the problem.
– Panagiotis Kanavos
Nov 8 at 9:35
@JeppeStigNielsen yes the list is not compatible with the type im trying to display
– Em44
Nov 8 at 13:55
How is EmployeeCollection declared? (what's its type?)
– johey
Nov 8 at 14:01