0

I have a table named Tags in which a new column is added when a user creates a tag (name of the column will be the tag name that the user gave). Also, the column is renamed when a user edits a tag name.

I know there is a design flaw in my application. But just wondering how are we supposed to create a model for such a table? Is there any way I could perform CRUD operation in such table using Entity Framework?

2
  • 2
    I think there is some design flaw if you are adding column for each entry. Commented Apr 16, 2019 at 3:42
  • Why not do a one column table and add a new record for each tag? Then you won’t run into this problem. Commented Apr 16, 2019 at 3:59

1 Answer 1

1

Except it is a very strange design the solution is quite simple - just execute raw SQL query, and do the manual mapping. Example query:

    string studentName = ctx.Database
           .SqlQuery<string>("Select tag1 from Posts where postId=@id", new SqlParameter("@id", 1))
           .FirstOrDefault();

All CRUD operations you can handle with raw queries.

Sign up to request clarification or add additional context in comments.

1 Comment

I did try this. It's working. I suppose it's the only easy way out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.