I try to get the right tables based on a string and user ID for the client inc another table taht belongs to it:
private List GetVocabularyScores(string scoreTableName, string userId)
{
using var db = this._context.CreateDbContext();
switch (scoreTableName)
{
case nameof(Vocabulary1Score):
return db.Vocabulary1Score
.Where(x => x.UserId == userId)
.Include(x => x.Vocabulary)
.Cast<IVocabularyXScore>()
.ToList();
case nameof(Vocabulary2Score):
return db.Vocabulary2Score
.Where(x => x.UserId == userId)
.Include(x => x.Vocabulary)
.Cast<IVocabularyXScore>()
.ToList();
etc etc
When I up cast it to the interface I get the limited object which doesn’t have the Vocabulary class since all VocabularyxScore has its own Vocabularyx.
public interface IVocabularyXScore
{
int Id { get; set; }
string UserId { get; set; }
ApplicationUser User { get; set; }
int VocabularyId { get; set; }
int Score { get; set; }
int CorrectCount { get; set; }
int IncorrectCount { get; set; }
DateTime? LongTermMemory { get; set; }
}
public class Vocabulary1Score : IVocabularyXScore
{
public int Id { get; set; }
public string UserId { get; set; }
[Required]
public ApplicationUser User { get; set; }
public int VocabularyId { get; set; }
[Required]
public Vocabulary1 Vocabulary { get; set; }
public int Score { get; set; }
public int CorrectCount { get; set; }
public int IncorrectCount { get; set; }
public DateTime? LongTermMemory { get; set; }
}
etc etc.
Now Ive rewatched some entity framework course of Mosh and im trying groupjoin and then adding it to an object.