mhenrixon
mhenrixon

Reputation: 6278

EF4 - POCO Problem

I was just trying to do some extensive model first using the self tracking POCO approach. I do however not get it to work as I wish. Let's take a blog. Each blog has a set of Entries and each Entry has a set of Comments. Unfortunately the following Model does not work for me. alt text http://blog.zoolutions.se/issue.png

The POCO class implementation looks like the following:

public class Blog
{
    public bool Id { get; private set; }
    public string Title { get; set; }
    public bool AllowComments { get; set; }
    public User User { get; set; }
    public IList<Entry> Entries { get; set; }
}

public abstract class Post
{
    public virtual int Id { get; set; }
    public virtual string Header { get; set; }
    public virtual string Text { get; set; }
    public virtual DateTime CreatedAt { get; set; }
    public virtual int UserId { get; set; }
}

public class Entry : Post
{
    public Blog Blog { get; set; }
    public IList<Comment> Comments { get; set; }        
}

public class Comment : Post
{
    public Entry Entry { get; set; }
}

This gives me a very strange error:

System.Data.MetadataException: Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Entry'. Previously found CLR type 'Entry', newly found CLR type 'System.Collections.Generic.Dictionary2+Entry'. The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Entry'. Previously found CLR type 'Entry', newly found CLR type 'System.Runtime.CompilerServices.ConditionalWeakTable2+Entry'.

Any clues? I can't wrap my head around that error message...

Upvotes: 1

Views: 2932

Answers (2)

timmi4sa
timmi4sa

Reputation: 644

Was unable to add this post under Alex James' reply.

EF4 still has a bug, something similar has already been fixed by Microsoft in EF 4 Beta 2.

I have encountered a bug when the classes with similar local names are stored within the assembly containing Entities, but belong to different EF4 edmx model files (ex: when Country entity exists in both GeographyConfigurationModel.edmx, and CustomerServiceModel.edmx). The two Country classes contain different sets of properties in each model and each model is located in a separate project folder, the entity namespace model property is specified (and promptly ignored).

Upvotes: 1

Alex James
Alex James

Reputation: 20914

In Beta1 the mapping for CLR classes to EDM types is somewhat unforgiving.

It sounds as if the problem here is that multiple 'Entry' classes have been found that don't match the required 'Entry' entity. We should just ignore those, but in Beta1 we don't and you get an exception.

We have worked on this for the next beta, so that instead the EF carries on looking for a matching class, and in your case would find your Entry class, and all would be okay.

Until Beta2 is released you will probably need to change the name of your Entry class to something a little more unique.

Hope this helps

Alex

Program Manager on the Entity Framework team.

Upvotes: 4

Related Questions