Link to home
Start Free TrialLog in
Avatar of ZenMasterZed
ZenMasterZed

asked on

'Cannot convert lambda expression to type'... Same code compiles ok in one class, not the other :O

I have an interesting occurence here... I have fairly basic code (using LINQ for entities with the MS entity framework beta from December) which compiles fine in one class. In another class, i repeated the original code and it comes up with an error.

"Cannot convert lambda expression to type 'string' because it is not a delegate type".
It's a very strange as the same code (ive intentionally made it the same now to show how weird this is!

The error points to the 'where' statement within the LINQ query. If i delete the working version, the busted version still fails. If i add another class with the same code, but never in the TargetRepository.

My 'workaround' is to create a new class and hope this doesn't crop up again.  Has anyone ever seen this behaviour... is this a known issue?  It makes me wonder that it might happen again which would not be helpful!!
public class DeploymentRepository
    {
        public void SelectTarget(string name)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DeploymentEntities"].ConnectionString;
            
            
            using (DeploymentEntities deploymentEntities = new DeploymentEntities(connectionString))
            {
                var targetOne =  (from target in deploymentEntities.Targets
                                  where target.MachineName == name
                                select target).FirstOrDefault();
            }
 
        }
 
 
    }
 
// Does not compile...
    public class TargetRepository
    {
        public void SelectTarget(string name)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DeploymentEntities"].ConnectionString;
 
 
            using (DeploymentEntities deploymentEntities = new DeploymentEntities(connectionString))
            {
                var targetOne = (from target in deploymentEntities.Targets
                                 where target.MachineName == name
                                 select target).FirstOrDefault();
            }
 
        }
    }
// weird !!!

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ZenMasterZed
ZenMasterZed

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Check your data file for the type of fields involved.
Avatar of ZenMasterZed
ZenMasterZed

ASKER

Data files were fine Jaime ( i had checked them quite thoroughly before posting here). It was literally a matter of removing the cs file and then replacing it. VS seemed to be 'holding on' to an older version.  There wasnt any problem with the code or data files themselves.  Thanks anyway :)