cmill02s
cmill02s

Reputation: 81

Entity Framework Combining Strings

What would be the best method to concatenate leadTag + content + EndTag into a string for entry into the database?

Here is my data model

namespace stories.Models
{
    public class StoryModels
    {
        [Key]
        public int id { get; set; }

        public DateTime? date { get; set; }

        [Required]
        public string title { get; set; }

        [Required]
        public string leadTag { get; set; }

        public string product { get; set; }

        public string user { get; set; }

        [Required]
        public string content { get; set; }

        public string EndTag { get; set; }
    }
}

Upvotes: 0

Views: 75

Answers (1)

Szymon
Szymon

Reputation: 43023

One way to do it would be to create another property in your model to combine the data. You could then use that property when writing to the database:

public string CombinedProperty
{
    get
    {
        return String.Format("{0}\n{1}\n{2}", leadTag, content, EndTag);
    }
}

Upvotes: 1

Related Questions