나는 주 사용자 테이블에 조인 된 테이블에서 데이터를 가져 오려고 시도했습니다. 두 번째 테이블은 이미지를 저장하는 것입니다. 아래에 게시 된 현재 코드는 ImagePath 필드를 가져올 때 테이블의 ImageID 만 반환합니다. 사용자가 많은 이미지를 추가 할 수 있으므로 별도의 테이블임을 유의하십시오. 테이블 조인 및 양쪽에서 데이터 가져 오기
이
은 모델입니다 :[Table("accountInfo")] // Table name
public class accountInfo
{
[Key]
public int AccountID { get; set; }
public int UserId { get; set; }
public int UserIdent { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public virtual ICollection<UserImages > UserImages { get; set; }
}
[Table("UserImages")] // Table name
public class UserImages
{
[Key]
public int ImageID { get; set; }
public int AccountID { get; set; }
public string ImagePath { get; set; }
public string ImageDesc { get; set; }
public int ProfileImage { get; set; }
}
컨트롤러 : 내가 설정 한 모델이 잘못 될 가정입니다
public ActionResult Index()
{
int id = (int)WebSecurity.CurrentUserId;
var users = db.AccountInformation.Include(c => c.UserImages).Where(c => c.UserId == id);
return View(users.ToList());
}
. 누구든지 도와 줄 수 있습니까?
"accountInfo"및 "AccountInformation"테이블이 있습니까? – siddharth
저는 시각적 인 webdevelopers 스캐 폴딩을 사용했습니다. 이것은 accountInfo와 직접 연관되어있는 것 같습니다. – user2029541