ASP.NET MVC 4 Entity Framework entity to get foreign key field from membership user profile table -


i have entities in separate project. 1 of entity needs refer userid in userprofile model in web project referencing entity project. can new foreign key entity (something expense entity class additional field expender primary key in userprofile membership table?)

namespace expenseassistant.entities {     /// <summary>     /// expense     /// </summary>     public class expenseentry     {         /// <summary>         /// gets or sets unique id of expense         /// </summary>         public virtual int id { get; set; }          /// <summary>         /// gets or sets description expense         /// </summary>         public virtual string expensedescription { get; set; }          /// <summary>         /// gets or sets amount spent         /// </summary>         public virtual float amount { get; set; }          /// <summary>         /// gets or sets expender userid userprofile table         /// </summary>         [foreignkey("userprofile")]         public virtual int expenderid { get; set; }     } } 

membership tables in same database in have entity tables.

i tried update-database in console after adding key expenderid in expenseentry entity, getting error below,

the foreignkeyattribute on property 'expenderid' on type 'expenseassistant.entities.expenseentry' not valid. navigation property 'userprofile' not found on dependent type 'expenseassistant.entities.expenseentry'. name value should valid navigation property name.

thanks in advance.

there 2 problems.

the first problem attribute meant used on navigation property (which don't seem have).

an example of such navigation property be:

public virtual userprofile expender { get; set; } 

the second problem name passed foreignkeyattribute constructor must name of property containing foreign key in class, not name of table or entity referenced foreign key.

this code should like:

public virtual int expenderid { get; set; }  [foreignkey("expenderid")]  public virtual userprofile expender { get; set; } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -