Problems with LINQ and Code Contracts
-
Tuesday, February 14, 2012 8:55 AM
Hi,
I'm getting some problems with the following LINQ query.
List<Member> methods = new List<Member>(); using (Tfs_CodeMetricsEntities db = new Tfs_CodeMetricsEntities()) { Contract.Assume(db != null); var x = from r in db.Run from tp in db.TeamProject from s in db.Solution from p in db.Project from n in db.Namespace from t in db.Type from m in db.Member where r.Id == tp.RunId && s.TeamProject.Id == tp.Id && p.SolutionId == s.Id && n.ProjectId == p.Id && t.NamespaceId == n.Id && t.Id == m.TypeId && r.BuildDefinitionStartTime == build.StartTime select m; if (x != null && x.Count() > 0) { methods = x.ToList<Member>(); } }I'm getting the Warnings:
CodeContracts: requires unproven: constructor != null
CodeContracts: requires unproven: source != null
Somebody knows how to solve this?
Thanks.
All Replies
-
Thursday, February 16, 2012 2:05 AMModerator
Hi juaprebo,
Welcome to MSDN Forum.
Based on the issue, I didn't find anything wrong with the Linq statement, I think the warning is caused by "Contract.Assume(db!=null);". I'm afraid I'm not familiar with Contract class. If you just want to judge whether the db is null, please try to use if statement instead, and to watch whether the warnings are disappear.
Best Regards
Allen Li [MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Allen Li - AI3Microsoft Contingent Staff, Moderator Monday, February 20, 2012 2:14 AM

