기본적인 문제에 불법 액세스 LinqToSQl와 회원은 ... 유형 예외
I가 다음 코드를 실행하는 방법IList<Gig> gigs = GetGigs().WithArtist(artistId).ToList();
GetGigs을() 메소드 내 데이터베이스에서 연주회를 가져옵니다 LinqToSql 통해 ...
그래서, 때 GetGigs() WithArtist (ArtistID 순) .ToList() 나는 다음과 같은 예외를 얻을 실행됩니다.
Member access 'ListenTo.Shared.DO.Artist Artist' of 'ListenTo.Shared.DO.Act' not legal on type 'System.Collections.Generic.List`1[ListenTo.Shared.DO.Act]
을
참고 확장 기능 "WithArtist는"이 같다고 :
public static IQueryable<Gig> WithArtist(this IQueryable<Gig> qry, Guid artistId)
{
return from gig in qry
where gig.Acts.Any(act => (null != act.Artist) && (act.Artist.ID == artistId))
orderby gig.StartDate
select gig;
}
나는 코드 (보다는 LinqToSQL를 통해 DB에서 공연의 컬렉션을 구성하는 방법() 메소드 GetGigs를 교체하는 경우) 나는 예외를 얻지 않는다.
그래서 개체 구조보다는 LinqToSQl 코드에 문제가 있음을 확신합니다.
그러나 LinqToSQl 버전이 작동하지 않는 이유를 알지 못하므로 아래의 모든 관련 코드를 포함 시켰습니다. 어떤 도움이라도 매우 감사하게 받아 들일 것입니다 !! 내가 법, 아티스트와 공연에 대한 코드를 포함했다
public IQueryable<ListenTo.Shared.DO.Gig> GetGigs()
{
return from g in DBContext.Gigs
let acts = GetActs(g.ID)
join venue in DBContext.Venues on g.VenueID equals venue.ID
select new ListenTo.Shared.DO.Gig
{
ID = g.ID,
Name = g.Name,
Acts = new List<ListenTo.Shared.DO.Act>(acts),
Description = g.Description,
StartDate = g.Date,
EndDate = g.EndDate,
IsDeleted = g.IsDeleted,
Created = g.Created,
TicketPrice = g.TicketPrice,
Venue = new ListenTo.Shared.DO.Venue {
ID = venue.ID,
Name = venue.Name,
Address = venue.Address,
Telephone = venue.Telephone,
URL = venue.Website
}
};
}
IQueryable<ListenTo.Shared.DO.Act> GetActs()
{
return from a in DBContext.Acts
join artist in DBContext.Artists on a.ArtistID equals artist.ID into art
from artist in art.DefaultIfEmpty()
select new ListenTo.Shared.DO.Act
{
ID = a.ID,
Name = a.Name,
Artist = artist == null ? null : new Shared.DO.Artist
{
ID = artist.ID,
Name = artist.Name
},
GigId = a.GigID
};
}
IQueryable<ListenTo.Shared.DO.Act> GetActs(Guid gigId)
{
return GetActs().WithGigID(gigId);
}
LinqToSQL 코드는 .... 아래의 객체 :
public class Gig : BaseDO
{
#region Accessors
public Venue Venue
{
get;
set;
}
public System.Nullable<DateTime> EndDate
{
get;
set;
}
public DateTime StartDate
{
get;
set;
}
public string Name
{
get;
set;
}
public string Description
{
get;
set;
}
public string TicketPrice
{
get;
set;
}
/// <summary>
/// The Act object does not exist outside the context of the Gig, therefore,
/// the full act object is loaded here.
/// </summary>
public IList<Act> Acts
{
get;
set;
}
#endregion
}
public class Act : BaseDO
{
public Guid GigId { get; set; }
public string Name { get; set; }
public Artist Artist { get; set; }
}
public class Artist : BaseDO
{
public string Name { get; set; }
public string Profile { get; set; }
public DateTime Formed { get; set; }
public Style Style { get; set; }
public Town Town { get; set; }
public string OfficalWebsiteURL { get; set; }
public string ProfileAddress { get; set; }
public string Email { get; set; }
public ImageMetaData ProfileImage { get; set; }
}
public class BaseDO: IDO
{
#region Properties
private Guid _id;
#endregion
#region IDO Members
public Guid ID
{
get
{
return this._id;
}
set
{
this._id = value;
}
}
}
}
나는이 같은 오류로 실행하고 내 경우에는 내 WHERE 절 내에서 상관 하위 쿼리의 사용과 관련된 것으로 보인다. 정보를 찾으면 업데이트를 드리겠습니다. – jpierson