asp.net mvc 4 - Error when projecting partial class properties. The specified type member 'Password' is not supported in LINQ to Entities -


i using mvc4 databasefirst ef 5. exception: "the specified type member 'password' not supported in linq entities."

enter image description here

my code:

auto generated class ef using db first approach

    // auto-generated-class     public partial class webpages_users     {         public int userid { get; set; }         public string username { get; set; }         public string email { get; set; }         public virtual icollection<webpages_usersmenus> webpages_usersmenus { get; set; }         public virtual icollection<webpages_roles> webpages_roles { get; set; }     } 

then created partial class password property. return blank value , value set view.

[metadatatype(typeof(webpages_users_md))] public partial class webpages_users {     public string password { {return ""; } }     class webpages_users_md     {     } } 

in below line exception when using password property:

    var userlist = repository.webpages_users.select(x => new { x.userid, x.username, x.password, x.email }).tolist(); // error!!! 

however, below works fine without password property

    var userlist = repository.webpages_users.select(x => new { x.userid, x.username, x.email }).tolist(); // no error here. ok. 

note: have use select() or excude icollection list otherwise jquery used in view give error.

i share answer struggling same issue refer this.

in partial class, password should set when form posted, controller property value mapped.

public string password { get; set; } 

and in controller when returning list view replace x.password password = "":

repository.webpages_users.select(x => new { x.userid, x.username, password = "", x.email }).tolist(); 

blank value set password property , returned view.

then jquery in view can set password property , when form posted, webpages_users.password value accessible


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -