开发者

Joining a database table with a Dictionary

I am trying to join a db table with a List of objects which have two values [int ID, double Value] where int - is ID in the table, and double is some percentage.

I want to get the result from the database with LINQ so that the result will be sorted by the double Value in the object.

Here i开发者_如何学Pythons a sample code:

var sortedDict = (from entry in SimilarDealPercentage orderby entry.Value descending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);

List<SimilarityRatio> temptable = new List<SimilarityRatio>();

foreach (KeyValuePair<int, double> pair in sortedDict)
            {
                SimilarDealIds.Add(pair.Key);
                SimilarityRatio sr = new SimilarityRatio();
                sr.ID = pair.Key;
                sr.Value = pair.Value;
                temptable.Add(sr);
            }
 var qfinal = from d in DB.Deals
                         from s in temptable
                         where (d.Id == s.ID)
                         orderby s.Value descending
                         select d;

This gives the following error:

Unable to create a constant value of type 'NineOwl.DAL.Managers.SimilarityRatio'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜