0

I'm trying to set a variable like so...

var userID = WebMatrix.WebData.WebSecurity.CurrentUserId;
var options = db.UserProfiles.Find(userID).TaskTypeSetting;

I'm using the user authentication table provided by the basic Internet Application template.

Row UserId in table UserProfile has a one-to-many relationship with row User in table TaskTypeSetting.

It is telling me that it cannot find a definition for TaskTypeSetting. Shouldn't I be able to do this if my relationships are set up properly?

Here is the model for the table:

namespace DailyTaskList.Models
{
    using System;
    using System.Collections.Generic;

    public partial class TaskTypeSetting
    {
        public int ID { get; set; }
        public int Type { get; set; }
        public int User { get; set; }
    }
}

It looks like it's not adding the relationship to the code? The .edmx diagram shows the relationships as I have them set up.

Edit:

UserProfile class definition:

namespace DailyTaskList.Models
{
    using System;
    using System.Collections.Generic;

    public partial class UserProfile
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
    }
}

Compiler Error Message: CS1061: 'DailyTaskList.Models.UserProfile' does not contain a definition for 'TaskSetting' and no extension method 'TaskSetting' accepting a first argument of type 'DailyTaskList.Models.UserProfile' could be found (are you missing a using directive or an assembly reference?)

I'm also getting this under Mapping Details:

Mappings are not allowed for an association over exposed foreign keys.
7
  • you getting a compile time error ? Commented Apr 28, 2014 at 17:17
  • Yes, it is a compilation error. Commented Apr 28, 2014 at 17:22
  • just look at your generated table objects and find out Commented Apr 28, 2014 at 17:25
  • I have added the code for that. It looks like the code is not being added for whatever reason. Is this an EF bug or something I did? Commented Apr 28, 2014 at 17:35
  • You really need to post the User and UserProfile class definitions. Based on what you are showing, your UserProfile needs to use the UserID as the PK identifier, allowing just ONE userProfile per user. I suspect there is no "sub" object within the userProfile class for a TaskTypeSetting, leading to your compile error. But I cannot say for certain what you are doing wrong without seeing the other classes Commented Apr 28, 2014 at 18:06

1 Answer 1

2

After some research, I've discovered that what I was experiencing was a bug with Visual Studio 2012 and Entity Framework. Entity Framework was failing to generate my code properly. This is caused by the .edmx file being nested within the project files.

The solution I used:

  • Right click on .tt file and select "Run Custom Tool"

Other solutions:

  • Update Visual Studios.
  • Drag .edmx out of the project folder.

I wrote a blog on the situation which can be found here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.