开发者

asp.net MVC fetching data with table relations

I have created my Database which has: Artist, tracks and TracksPerArtists

I开发者_JAVA百科 can do sql queries through the entity model. For example when I make:

database.TRACK.ToList()

I get the list of track to be shown on index view for example. But my foreign keys come empty. While there is an artist and a track, and the correct row for ArtistsPerTrack, this item in my track.ToList() collection is empty.

Is there a different way to fetch those data?

I came from cakePHP framework in which you can define the Model.recursive property to declare the depth of the relations you want to fetch.

Is there anything similar here?


There is something similar. If "database" is DataContext and Artist and Tracks have many to many relationship in database, you can fetch related entities using Include clause:

database.TRACK.Include("Artists").ToList()

where "Artists" is the name of property on Track entity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜