Q:

How to manipulate strings in the Model for MVC

I'm creating a ASP.NET project and I have a CustomerModel generated by Entity Framework (because database first). I'm trying to manipulate a Name field so I can separate it into a FirstName and LastName respectively. Here's my model:
public partial class Customer
{
    public int CustomerID { get; set; }
    public string Name { get; set; }
    ...

    // something like this?
    // I know this will cause an error though
    FirstName = Name.Substring(0, Name.IndexOf(" "));

Am I correct when I manipulate it like this? Also would this affect anything when I, for instance, create data and it the value goes to variable instead of field.

A:

How do you know that a person doesn't enter three or four names?  A lot of people have middle names.  How would you handle that logically?  What about people with names where their last name is two parts like Van Pelt or Saint James?  
If you can somehow define that, you can use logic in your setter for the Name property.  When it's set, split it to its various parts.  Here's a simple example:
    public class NameExample
    {
        private string name;
        private string firstName;
        private string lastName;

        public string Name
        {
            get { return name;  }
            set
            {
                if( value != name )
                {
                    name = value;
                    if (string.IsNullOrEmpty(name)) return;
                    var names = name.Split(' ');
                    firstName = names[0];
                    if (names.Length > 1) lastName = names[1]; // Is our person Cher? ;-)
                }
            }
        }

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                firstName = value;
                name = firstName + (string.IsNullOrEmpty(lastName) ? "" : " " + lastName);
            }
        }

        public string LastName
        {
            get => lastName;
            set {
                lastName = value;
                name = firstName + (string.IsNullOrEmpty(lastName) ? "" : " " + lastName);
            }
        }

You can do this with Entity Framework since it actually calls the setters for the properties when it loads the values from the database.  And it calls the getters to get the values to write to the database. This is why you must use public  properties instead of public fields for domain models.
My example is deliberately verbose and quick.  You can fine tune it hoever you want.

