Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:35:14+00:00 2026-06-18T09:35:14+00:00

I have a class course like this: public class course { public int CourseID

  • 0

I have a class course like this:

public class course   
{
        public int CourseID { get; set; }
        public string Name { get; set; }   
        public Event Schedule {get; set;} //Event is coming from library Dday.iCal  
}     

Entity framework cannot correctly understand on how to save this property. ( I want to serialize it to string when saving, and keep it as event when worknig with it in my application.) So I have two methods, say, SerializeToString() and DeserializeFromString(). I want those methods to be applied only when saving to database.

What I came up with the following. Basically I’m trying to have a separate property as a string that will be saved in the database and Event will be ignored, but it doesn’t save anything to the database now. I’m not even sure if this is a good approach to do things, or there’s something better that can be done.:

 public class course   
    {
            public int CourseID { get; set; }
            public string Name { get; set; }  
            private Event _Schedule;
            [NotMapped]  
            public Event Schedule {  
            get
            {
                if (!String.IsNullOrEmpty(CourseSchedule))
                {
                    return DeserilizeFromString(CourseSchedule);
                }
                return new Event();
            }
            set
            {
                _schedule = value;
            }
            }  
            private string _courseSchedule;
            public string CourseSchedule { 
            get
            {
                return _courseSchedule;
            }
            private set
            {
                if (Schedule != null)
                {
                    _courseSchedule = SerializeToString(Schedule);
                }
                else
                {
                    _courseSchedule = null;
                }
            }   
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:35:15+00:00Added an answer on June 18, 2026 at 9:35 am

    You should keep your models as minimalistic as possible, just the auto-properties and attributes. For more complex business logic it’s good to add another layer to your MVC pattern. This one is usually called Repository (hard to find a good tutorial on Repository Pattern though.. 🙁 )and comes between model and controller controller.

    This also is very useful for performing unit tests. When properly implemented it allows you to do replace database dependency with collection during tests. This approach will require a bunch of additional work on the project.

    One more approach (a simpler one) would be to add a ViewModel layer. Do it this way:

    class MyModel
    {
        public string Text { get; set; }
    }
    
    class MyViewModel : MyModel
    {
        public new string Text
        {
            get { return base.Text; }
            set { base.Text =value.ToUpper(); }
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            MyViewModel mvm = new MyViewModel();
            mvm.Text = "hello there";
            var s = ((MyModel) mvm).Text; // "HELLO THERE"
        }
    }
    

    In DataContext use MyModel in controller use MyViewModel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the a class Foo like this: class Foo { public int id{get;set;}
I have a list of string like this : public List<string> Subs { get;
I have something like this: class Base { public: static int Lolz() { return
I have a class: public class MyClass { public int code { set; get;
I have created a class student with three properties like this public class Student
I have these two class(table) @Entity @Table(name = course) public class Course { @Id
I have a class: public class PointD { public double X { get; set;
Let's say I have a class with a public property inside, like this: class
Suppose you have 2 classes like so: public class ClassA { public int X
I have class with back reference: public class Employee : Entity { private string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.