0

I have designed 2 tables to store data.

enter image description here

enter image description here

If I want to just show a list of tables with 2 columns and the column value, how should I write my LINQ query in C#?

I can't even pivot it using SQL. This my query

SELECT FieldValue, recordid
  FROM [TableMetadatas] t inner join TableMetadataTemplates t2
  on t.[TableMetadataTemplateId] = t2.id
  where (FieldName = 'application_name' or fieldname = 'application_category') 
  and TableName = 'application'
  group by t.FieldValue,  t.recordid
  order by recordid

Problem is each row is each field value instead of each record.

Application 1
application_type value 1
Application 2
application_type value 2

The expected result should be below:

Application 1 | application_type value 1
Application 2 | application_type value 2
Steve
  • 2,963
  • 15
  • 61
  • 133
  • 1
    Unless you have a very, very good reason for this specific design, I would recommend avoiding it. The Entity-Attribute-Value (EAV for short) design is not very compatible with relational databases and usually prevents using most if not all the benefits a relational database can give you for storing data over a simple text-based storage such as json or xml. For more information, read https://stackoverflow.com/a/2224267/3094533 – Zohar Peled Jan 10 '23 at 07:22

0 Answers0