locked
The type arguments cannot be inferred from the query... RRS feed

  • Question

  • I'm getting a "The type arguments cannot be inferred from the query" for the following linq query:

    IQueryable<EquivalencySummary> query = from equivalency in Models.Equivalencies
    	join inventory in Models.Inventories on new
    	{
    		equivalency.EquivalencySupplier,
    		equivalency.EquivalencyPart
    	} equals new
    	{
    		inventory.Supplier,
    		inventory.Part
    	}
    	select new EquivalencySummary
    	{
    		EquivalencySupplier = equivalency.EquivalencySupplier,
    		EquivalencyPart = equivalency.EquivalencyPart,
    		EquivalencyItemDescription = inventory.Description1,
    		Supplier = equivalency.Supplier,
    		Part = equivalency.Part
    	};

    If I take out the anonymous type and just join on one of the fields or another the error goes away, but obviously I need to join on both fields. All fields being compared are strings. This is a pretty straight forward query so i'm not sure what the problem is exactly. Any help would be greatly appreciated, thanks!

    Friday, August 2, 2013 9:34 PM

Answers

  • Hi jfk1974;

    Try the join as follows. The two anonymous type must be of the same type. The datatype may be the same but the names used in both are different.

    join inventory in Models.Inventories on new
    	{
    		Supplier = equivalency.EquivalencySupplier,
    		Part = equivalency.EquivalencyPart
    	} equals new
    	{
    		Supplier = inventory.Supplier,
    		Part = inventory.Part
    	}

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by jfk1974 Monday, August 5, 2013 2:29 PM
    Saturday, August 3, 2013 2:05 AM

All replies

  • Hi jfk1974;

    Try the join as follows. The two anonymous type must be of the same type. The datatype may be the same but the names used in both are different.

    join inventory in Models.Inventories on new
    	{
    		Supplier = equivalency.EquivalencySupplier,
    		Part = equivalency.EquivalencyPart
    	} equals new
    	{
    		Supplier = inventory.Supplier,
    		Part = inventory.Part
    	}

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by jfk1974 Monday, August 5, 2013 2:29 PM
    Saturday, August 3, 2013 2:05 AM
  • I knew it had to be something easy, thanks!
    Monday, August 5, 2013 2:29 PM