开发者

Linq query for EAV

I have a big (4M records) table on a SQL Server with the following columns:

  • Id (a record identifier);
  • PropertyName (a string that represents a property name);
  • PropertyValue (an integer that represent the property's value);

keep in mind that Id is not unique for this table. Basically, I'd开发者_StackOverflow like to write a LINQ query that retrieves Ids and all its associated PropertyName/PropertyValue pairs:

  • Id
  • dictionary (maybe?) PropertyName -> PropertyValue;

is this feasible in some way?

Thank you in advance


Not sure regarding performance but you can use GroupBy to group your data by similar Ids

Something like:

var result =
  from x in whatever
  group x by x.Id into g
  select new { 
         Id = g.Key, 
         Data = g.ToDictionary(i => i.PropertyName, i => i.PropertyValue)
  };

Refer to 101 LINQ Samples to learn more about Linq

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜