You can not create a User
directly mapped to the Database. If you want to do a new User
you must create a UserDTO
to do it. I explain:
First Create your class DTO :
public class UserDTO
{
public string CommpleteName{ get; set; }
// Crea las columnas que necesites (mismo nombre que en base de Datos)
}
Edit your method so that instead of returning a User
it returns a UserDTO
:
var result = db.Users.Select(x => new UserDTO() {CommpleteName=x.CommpleteName}).FirstOrDefault();
To clarify a bit. If you have in Entity FrameWork your model User
with the following fields:
Id
Nombre
Apellido
CommPleteName
FechaNacimiento
You create class UserDTO
:
public class UserDTO
{
public int Id{ get; set; }
public string Nombre{ get; set; }
public string Apellido{ get; set; }
public string CommpleteName{ get; set; }
public DateTime? FechaNacimiento{ get; set; }
}
In this way any query with linq
that attacks User
what you will do is create the entity UserDTO
.