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









share|improve this question
























  • 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










  • 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















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









share|improve this question
























  • 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










  • 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













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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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










  • 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












  • 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












  • @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












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 Checkinouts.






share|improve this answer





















  • 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











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',
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%2f53204357%2fcannot-implicity-convert-list%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








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 Checkinouts.






share|improve this answer





















  • 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















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 Checkinouts.






share|improve this answer





















  • 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













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 Checkinouts.






share|improve this answer












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 Checkinouts.







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















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.





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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()