0

I am building a library for Windows Phone 8 which requires local databases. For obvious reasons, user of the library is going to create a mappable LINQ-to-SQL class with appropriate [Table]s and [Column]s. However, To in every such class, I need a few more columns for internal functioning of the library. The idea was that I would include a base class in the library which will have members corresponding to the required columns. The user would simply inherit from this class, add his own members and use that class as final LINQ-to-SQL map.

So far, my base class looks like this:

//Class to contain all the essential members
[Table]
public class SyncableEntityBase : NotifyBase, ISyncableBase
{
    [Column(DbType = "INT NOT NULL IDENTITY", IsDbGenerated = true, IsPrimaryKey = true)]
    public int ItemId { get; set; }

    [Column]
    public bool IsDeleted { get; set; }

    [Column]
    public DateTime RemoteLastUpdated { get; set; }

    [Column]
    public DateTime LocalLastUpdated { get; set; }       
}

And the derived class, something like this:

[Table]
public class ToDoCategory : SyncableEntityBase
{
    private string _categoryName;
    [Column]
    public string CategoryName
    {
        get
        {
            return _categoryName;
        }
        set
        {
            if (_categoryName != value)
            {
                NotifyPropertyChanging("CategoryName");
                _categoryName = value;
                NotifyPropertyChanged("CategoryName");
            }
        }
    }

    private string _categoryColor;
    [Column]
    public string CategoryColor
    {
        get
        {
            return _categoryColor;
        }
        set
        {
            if (_categoryColor != value)
            {
                NotifyPropertyChanging("CategoryColor");
                _categoryColor = value;
                NotifyPropertyChanged("CategoryColor");
            }
        }
    }
}

Idea is to have final class with the four essential columns and two added by user. According to MSDN documentation here, I need to append [InheritanceMapping] which requires the inherited type. However, as I am building a library, I have no way to know what types (and how many) the user will derive from my base class. Is there any way around this? How?

7
  • maybe you can use this instead: blogs.msdn.com/b/dinesh.kulkarni/archive/2007/11/09/… Commented Sep 30, 2013 at 12:39
  • @ErikEJ This approach basically enforces the user to implement properties. User still has to do the work which shouldn't be necessary as the properties should absolutely be there - without any change by user. Secondly, I just wrote interface instead of an abstract class. How does it compare? Commented Sep 30, 2013 at 13:04
  • I think you are going for an impossible task, maybe use code generation approach? (I could help you there) Commented Sep 30, 2013 at 13:11
  • @ErikEJ I am okay with whatever approach works. The ultimate idea is to achieve the thing here via a library. In the link above, the guy seems to be able to do what I'm doing quite happily using SQLite. Moreover, he's also got CreateTable method which could solve my question here. Commented Sep 30, 2013 at 13:22
  • Yes, but I think it will not be possible with SQL CE... Commented Sep 30, 2013 at 13:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.