Код: Выделить всё
SongКод: Выделить всё
public class Song
{
public int Id { get; set; }
public string AudioName { get; set; }
public string ArtistName { get; set; }
...
public virtual ICollection SimilarVersions { get; set; } = new List();
}
public class SimilarVersion
{
public int Id { get; set; }
public int? Song_Id1 { get; set; }
}
< /code>
Просмотреть модели: < /p>
public class SongDto
{
public int Id { get; set; }
public string AudioName { get; set; }
public string ArtistName { get; set; }
...
public ICollection SimilarSongDtos { get; set; } = new List();
}
public class SimilarSongDto
{
public int Id { get; set; }
public string AudioName { get; set; }
public string ArtistName { get; set; }
...
}
Код: Выделить всё
Song_IdКод: Выделить всё
Song_Id1Код: Выделить всё
_similarVersionService.GetSimiliarVersion().Song_IdКод: Выделить всё
public ActionResult Song(int id)
{
//Map the domainModel to songViewModel
var songDto = Mapper.Map(_songService.GetSong(id));
//Get all of the songs where the id == the Song_Id column in similar version table
var songs = _songService.GetSongs().ToList()
.Where(x => x.SimilarVersions.Any(z => z.Song_Id == songDto.Id))
.ToList(); //z.Song_Id no definition found
//Map the Song domain to SimilarSong ViewModel and assign it to the songDto to be passed to the view
songDto.SimilarSongDtos = Mapper.Map(songs);
return View(songDto);
}
< /code>
[b] Редактировать. Попытка добавить в строку на основе Admir Ответ: [/b]
var songToUpload = new Song
{
AudioName = uploadSongDtos[i].AudioName.Trim(),
ArtistName = uploadSongDtos[i].ArtistName,
};
foreach (var compareAgainstString in _songService.GetSongs().ToDictionary(x => x.Id, x => x.AudioName))
{
var score = SearchContext.Levenshtein.iLD(songToUpload.AudioName, compareAgainstString.Value);
//Don't add the current song
if (score < 50 && songToUpload.Id != compareAgainstString.Key)
songToUpload.SimilarVersionsWhereSimilar.Add(new SimilarVersion { SimilarId = compareAgainstString.Key });
}
Подробнее здесь: https://stackoverflow.com/questions/373 ... oreign-key
Мобильная версия