0

Like I mentioned in this question, I wanted to rename some auto generated properties.

So I use the following partial class

    public partial class Plan
    {
        public Profile Creator
        {
            get { return this.Profile; }
            set
            {
                this.Profile = value;
            }
        }

        public Profile Guest
        {
            get { return this.Profile1; }
            set
            {
                this.Profile1 = value;
            }
        }
    }

to avoid using Profile1 and Profile. It works but I can't use these new properties in a where clause because they are not mapped (well that's my guess).

Example:

myQuery.Where(x => x.Creator.User.UserName == userName)

I have the following exception

The specified type member 'Creator' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

I tried to map the property like this but without any success

[Column("creator_id", TypeName="int")]
public Profile Creator
{
    get { return this.Profile; }
    set
    {
        this.Profile = value;
    }
}

Is it possible?

Community
  • 1
  • 1
Marc
  • 16,170
  • 20
  • 76
  • 119

1 Answers1

0

i think you are looking for something like this

  [ForeignKey("creator_id")]
  public virtual Profile Creator { get; set; }

These things you commonly use for a code first approach. If you have an existing database you can reverse engineer your code first. check out http://msdn.microsoft.com/en-us/data/jj200620.aspx for an example. That way you can use the fluent API toolkit and an existing database. the best of two worlds.

Batavia
  • 2,497
  • 14
  • 16