Question

Is it possible to convert the column (stored as comma delimited) to be presented in the edmx designer as another entity?

table structure

student
  id
  name
  subjects << this is the comma delimited column (1,2,3,10)

subject
  id
  name

EDMX designer structure would be

student 
  id
  name

student_subject
  studentId
  subjectid

subject
  id
  name   

If so, can someone point me on how to do it on EF designer.

NOTE: I cannot change the table structure and I'm using database first

thanks

Was it helpful?

Solution

There is no way to do this. Worse: in SQL it might be possible to fetch the subjects with an IN clause, but with linq you haven't even got that option. I'm afraid what's left is a painstaking linq-to-objects operation where you first grab the Student from the database, then parse the subjects in an int array, and finally grab the Subjects with a Contains query:

var subjectIds = student.Subjects
    .Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
    .Select (x => int.Parse(x));

var subjects = context.Subjects.Where(s => subjectIds.Contains(s.Id));

(And don't forget to send the architect as student to a course with subject 'Data base design')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top