TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guillermo Perez
NA
27
405
Generic Local Function and List
Sep 12 2020 4:20 PM
Thank you for reading! I'm getting a list of objects (from a dbcontext), then I created a method to pass this list to a Local Function, the method accepts the list but when I try to loop, instead of being able to show the content of my object members I get an error saying: "'T' does not contain a definition for 'Id' and no accessible extension method 'Id' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?) " And this problem is not only with Id, I can't access any of the properties, please check the code: would you please help me find what I am missing? thank you for your advice.
public
IActionResult Racks()
{
List<OldRackAustin> mylist = db.OldRacksAustin.ToList<OldRackAustin>();
ProcessMyList(mylist);
void
ProcessMyList<T>( List<T> list)
{
foreach
(T item
in
list)
{
Debug.WriteLine(item.Id); /* PROBLEMATIC LINE */
}
}
return
Json(
"done"
);
}
And the DBcontext entity (object) looks like...
[Table(
"OLD-Racks-Austin"
)]
public
class
OldRackAustin
{
[Key]
public
int
Id {
get
;
set
; }
public
string
Rack_Type {
get
;
set
; }
public
string
Serial_Number {
get
;
set
; }
public
short
Pages {
get
;
set
; }
public
int
? Rack_Capacity {
get
;
set
; }
public
string
Status {
get
;
set
; }
public
string
Type {
get
;
set
; }
public
string
Subtype {
get
;
set
; }
}
Reply
Answers (
1
)
Mobile App develpement
Assist with Question