locked
The type '<>f__AnonymousTypee …' exists in both … and 'EntityFramework.dll RRS feed

  • Question

  • Hello,

    I have the following query:

    var result = context.Questions
      .Where(x =>
        x.Access >= 1 &&
        x.Enabled == true
      )
      .Select(y => new {
        Duration = y.Duration,
        Answers = y.Answers.Select(z => new {
          Text = z.Text,
          Packs = z.Packs.SelectMany(u => u.Files, (u, v) => new {
            Flag = u.Flag,
            File = new { Key = v.Key }
          }),
        })
      })
      .GroupBy(w => w.Duration)        
      .ToList();

    I get 8 groups but when I try to expand the Result View in each group I get the error: Results View = The type '<>f__AnonymousTypee' exists in both 'MyProject.Data.dll' and 'EntityFramework.dll'

    If I remove the GroupBy then I am able to expand all items.

    What am I doing wrong?

    Thank You,

    Miguel

    Sunday, March 10, 2013 1:18 AM

All replies

  • Hi Miguel;

    Try changing the order of the two properties of the anonymous type, something like this. Because the error being given states that this same anonymous type is defined in the two dll's. By changing the order you are creating a anonymous type that is NOT the same as the other.

      .Select(y => new {
        Answers = y.Answers.Select(z => new 
            {
                Text = z.Text,
                Packs = z.Packs.SelectMany(u => u.Files, (u, v) => new 
                {
                    Flag = u.Flag,
                    File = new { Key = v.Key }
                })
            }),
        Duration = y.Duration
      })
    



    Fernando (MCSD)

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

    Sunday, March 10, 2013 2:38 AM
  • On 3/9/2013 8:18 PM, MDMoura wrote:

    <snipped>

    I believe you have a circular reference going between MyProject.Data.dll   and EntityFramework.Dll. I remember I had a similar problem not related to a Linq query, and I had to get the references straighten out.

    <http://forums.asp.net/t/980517.aspx/2/10>

    <http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/3091f8d5-4c3c-487c-88d2-da45cc15c250/>

    Sunday, March 10, 2013 3:06 AM
  • Hello,

    I changed the direction of all properties but I get the same error ...

    Can this error be generated by the fact I have the following entities:

      public class Question {
    
        public Int32 Id { get; set; }
        public Int32 Duration { get; set; }
        public String Text { get; set; }
    
        public virtual ICollection<Answer> Answers { get; set; }
        public virtual ICollection<Pack> Packs { get; set; }
    
      } // Question
      public class Answer {
    
        public Int32 Id { get; set; }
        public String Text { get; set; }
    
        public virtual Question Question { get; set; }
        public virtual ICollection<Pack> Packs { get; set; }
    
      } // Answer

    Both Question and Answer have a Many to Many relationship to Packs trough QuestionsPacks and AnswersPacks tables.

    I don't see why this would be a problem ... I am just placing all files in a centralized place.

    Thank You,

    Miguel

    Sunday, March 10, 2013 12:34 PM
  • Hi Miguel;

    What type of project is this in? Also is this Code First?

      


    Fernando (MCSD)

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

    Sunday, March 10, 2013 2:01 PM
  • Hello,

    Sorry for the delay. I didn't receive the email notification of your post.

    This particular code is in a class library and I am using EF5.

    I defined the entities, entities configuration, context and so on ...

    Everything is working fine. I am having only this problem.

    NOTE: I am not creating the database from my entities.

               The database has already been created.

    Thank You,

    Miguel

    Thursday, March 14, 2013 6:40 PM
  • Have you looked at darnold924 two links?

      


    Fernando (MCSD)

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

    • Marked as answer by MDMoura Thursday, March 14, 2013 7:00 PM
    • Unmarked as answer by MDMoura Thursday, March 14, 2013 7:00 PM
    Thursday, March 14, 2013 6:55 PM
  • Have you looked at darnold924 two links?

    Yes I did,

    But my class library has only a reference to Entity Framework and to another class.

    And the other class, also created by myself, does not have any reference to Entity Framework.

    Thursday, March 14, 2013 7:02 PM
  • The error you are getting leads me to believe that some how two anonymous types are being created that conflict with each other. Without seeing the code it is difficult to say what is going on. Can you post the code?

      


    Fernando (MCSD)

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

    Thursday, March 14, 2013 7:08 PM
  • The error you are getting leads me to believe that some how two anonymous types are being created that conflict with each other. Without seeing the code it is difficult to say what is going on. Can you post the code?

    Sure I can. You mean the entities, right?

    Looking at my code I think I know where the problem is.

    I am using a single table to hold all files of the application.

    The table Packs is only to hold multiple file versions of the same file.

    So a Question has a Many to Many relationship with Packs.

    And an Answer also has a Many to Many relationship with Packs.

    And a Question has many Answers.

    Might this be the problem?

    In terms of SQL I don't see a problem it this. Correct me if I am wrong.

    Anyway, here is my code:

      public class Question {
        public Int32 Id { get; set; }
        public Int32 Access { get; set; }
        public Int32 Duration { get; set; }
        public Boolean Enabled { get; set; }
        public String Text { get; set; }
        public virtual ICollection<Answer> Answers { get; set; }
        public virtual ICollection<Pack> Packs { get; set; }
      } // Question
    
      public class Answer {
        public Int32 Id { get; set; }
        public String Text { get; set; }
        public virtual Question Question { get; set; }
        public virtual ICollection<Pack> Packs { get; set; }
      } // Answer
    
      public class Pack {
        public Int32 Id { get; set; }
        public String Flag { get; set; }
        public virtual ICollection<File> Files { get; set; }
        public virtual ICollection<Answer> Answers { get; set; }
        public virtual ICollection<Question> Questions { get; set; }
      } // Pack
    
      public class File {
        public Int32 Id { get; set; }
        public Byte[] Data { get; set; }
        public Guid Key { get; set; }
        public virtual Pack Pack { get; set; }
      } // File
    

    Thank You,

    Miguel

    Thursday, March 14, 2013 7:45 PM
  • Can you also post your Linq queries as well please.

      


    Fernando (MCSD)

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

    Thursday, March 14, 2013 8:02 PM
  • Can you also post your Linq queries as well please.

    Hello,

    It is the Linq query I posted on my first post:

    var result = context.Questions
      .Where(x =>
        x.Access >= 1 &&
        x.Enabled == true
      )
      .Select(y => new {
        Duration = y.Duration,
        Answers = y.Answers.Select(z => new {
          Text = z.Text,
          Packs = z.Packs.SelectMany(u => u.Files, (u, v) => new {
            Flag = u.Flag,
            File = new { Key = v.Key }
          }),
        })
      })
      .GroupBy(w => w.Duration)        
      .ToList();
    Is this what you mean?
    Thursday, March 14, 2013 8:12 PM
  • Hi Miguel;

    I am sorry but this is not making sense to me. Can you zip up your project and post it to your SkyDrive and post the link to it here so I can have a look?

      


    Fernando (MCSD)

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

    Friday, March 15, 2013 5:03 AM