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 6529437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:38:06+00:00 2026-05-25T09:38:06+00:00

I’m trying to create a simple database to use sqlce in a windows phone

  • 0

I’m trying to create a simple database to use sqlce in a windows phone app.
I have a base class, and another set of classes that derive from it
Here’s what i got

public abstract class EntityBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

        private int id;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int EntityId
        {
            get
            {
                return id;
            }
            set
            {
                if (id != value)
                {
                    id = value;
                    OnPropertyChanged("Id");
                }
            }
        }
    }

    [Table]
    public class Derived : EntityBase 
    {
        [Column]
        public string Description
        {
            get;
            set;
        }
    }

Then, I’ve got this class for datacontext purposes:

public class MyDataContext : DataContext
    {
        // Specify the connection string as a static, used in main page and app.xaml.
        public static string DBConnectionString = "Data Source=isostore:/ToDo.sdf";

        // Pass the connection string to the base class.
        public MyDataContext(string connectionString)
            : base(connectionString)
        { }

        public Table<Derived> Deriveds;
    }

And finally, here i’m trying to create the db :

private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            using (MyDataContext db = new MyDataContext(MyDataContext.DBConnectionString))
            {
                if (db.DatabaseExists() == false)
                {
                    //Create the database -> here's the error
                    db.CreateDatabase();
                }
            }
        }

I’m getting the following error when trying to create the database :

Invalid column ID. [ EntityId ]

Yes, a very descriptive error message…
Any ideas on what’s wrong? I’ve been tampering around with the attributes in the column but to no avail.

[EDIT] : for what i’ve been testing, if i put the EntityId property in the derived class, it doesn’t crash. This can be 2 things.. one, that I’m missing something else in the base class, or the other one, that the column attribute for a primary key must belong to the class, and can’t belong to the parent (which would be a extremely horrible design decision, we can’t use inheritance???). if someone can confirm this that would be appreciated

  • 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-05-25T09:38:07+00:00Added an answer on May 25, 2026 at 9:38 am

    Ok, i think i found what was happening. In this implementation of SQLCe, we need to do the following approach when using inheritance :

    http://msdn.microsoft.com/en-us/library/bb399352(v=VS.100).aspx

    I don’t particularly like it very much, the tables that it generates aren’t normalized, but well, it’s true that we shouldn’t be using huge and complex datastores for WP7 apps, it’s more to store some basic info that’s too much to handle by isolated storage on itself..
    Following this approach, it worked. I have now a collection of the base class, and i can put into it any of it’s derived children. Then to retrieve them back, I use the discriminator in a linq to sql query to get one derived class or another.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.