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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:06:58+00:00 2026-06-17T13:06:58+00:00

For a school project we have to make a Windows Phone 7.1 application. It

  • 0

For a school project we have to make a Windows Phone 7.1 application. It has to use a local database, and we have to use LINQ and Bing Maps for this.

We are making an application that will retrieve routes from a database. Each route has some waypoints.

Now, we made 3 tables (more actually, but only those 3 are relevant at the moment), namely “Route”, “Waypoint” and “RouteWaypointLink”. You can see their classes below

Route:

[Table]
public class Route : INotifyPropertyChanged, INotifyPropertyChanging
{
    public event PropertyChangingEventHandler PropertyChanging;
    public event PropertyChangedEventHandler PropertyChanged;

    private int idRouteValue;
    private string nameValue;

    [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public int IDRoute
    {
        get
        {
            return idRouteValue;
        }
        private set
        {
            NotifyPropertyChanging("IDRoute");
            idRouteValue = value;
            NotifyPropertyChanged("IDRoute");
        }
    }
    [Column]
    public string Name
    {
        get
        {
            return nameValue;
        }
        set
        {
            NotifyPropertyChanging("Name");
            nameValue = value;
            NotifyPropertyChanged("Name");
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="propertyName"></param>
    private void NotifyPropertyChanging(string propertyName)
    {
        if (PropertyChanging != null)
        {
            PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="propertyName"></param>
    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public override string ToString()
    {
        return "[" + IDRoute + "] " + Name;
    }
}

Waypoint:

[Table]
public class Waypoint : INotifyPropertyChanged, INotifyPropertyChanging
{
    public event PropertyChangingEventHandler PropertyChanging;
    public event PropertyChangedEventHandler PropertyChanged;

    private int idWaypointValue;
    private string nameValue;
    private double gpsLongitudeValue;
    private double gpsLatitudeValue;
    private string descriptionValue;

    [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public int IDWaypoint
    { 
        get 
        {
            return idWaypointValue; 
        } 
        private set 
        {
            NotifyPropertyChanging("IDWaypoint");
            idWaypointValue = value;
            NotifyPropertyChanged("IDWaypoint"); 
        }
    }
    [Column]
    public string Name
    {
        get
        {
            return nameValue;
        }
        set
        {
            NotifyPropertyChanging("Name");
            nameValue = value;
            NotifyPropertyChanged("Name");
        }
    }
    [Column]
    public double GPSLongitude 
    {   
        get
        {         
            return gpsLongitudeValue;    
        }  
        set 
        {
            NotifyPropertyChanging("GPSLongitude"); 
            gpsLongitudeValue = value;
            NotifyPropertyChanged("GPSLongitude");  
        }
    }
    [Column]
    public double GPSLatitude
    {
        get
        {
            return gpsLatitudeValue;
        }
        set
        {
            NotifyPropertyChanging("GPSLatitude");
            gpsLatitudeValue = value;
            NotifyPropertyChanged("GPSLatitude");
        }
    }
    [Column]
    public string Description
    {
        get
        {
            return descriptionValue;
        }
        set
        {
            NotifyPropertyChanging("Description");
            descriptionValue = value;
            NotifyPropertyChanged("Description");
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="propertyName"></param>
    private void NotifyPropertyChanging(string propertyName)
    {
        if (PropertyChanging != null)
        {
            PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="propertyName"></param>
    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public override string ToString()
    {
        return Name;
    }
}

RouteWaypointLink:

[Table]
public class RouteWaypointLink : INotifyPropertyChanged, INotifyPropertyChanging
{
    public event PropertyChangingEventHandler PropertyChanging;
    public event PropertyChangedEventHandler PropertyChanged;

    private int idRouteWaypointLinkValue;
    private EntityRef<Route> routeValue;
    private EntityRef<Waypoint> waypointValue;
    private int waypointIndexValue;

    [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public int IDRouteWaypointLink
    {
        get
        {
            return idRouteWaypointLinkValue;
        }
        private set
        {
            NotifyPropertyChanging("IDRouteWaypointLink");
            idRouteWaypointLinkValue = value;
            NotifyPropertyChanged("IDRouteWaypointLink");
        }
    }

    [Association(IsForeignKey = true, Storage = "routeValue")]
    public Route Route
    {
        get
        {
            return routeValue.Entity;
        }
        set
        {
            NotifyPropertyChanging("Route");
            routeValue.Entity = value;
            NotifyPropertyChanged("Route");
        }
    }

    [Association(IsForeignKey = true, Storage = "waypointValue")]
    public Waypoint Waypoint
    {
        get
        {
            return waypointValue.Entity;
        }
        set
        {
            NotifyPropertyChanging("Waypoint");
            waypointValue.Entity = value;
            NotifyPropertyChanged("Waypoint");
        }
    }

    [Column]
    public int WaypointIndex
    {
        get
        {
            return waypointIndexValue;
        }
        set
        {
            NotifyPropertyChanging("Index");
            waypointIndexValue = value;
            NotifyPropertyChanged("Index");
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="propertyName"></param>
    private void NotifyPropertyChanging(string propertyName)
    {
        if (PropertyChanging != null)
        {
            PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="propertyName"></param>
    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public override string ToString()
    {
        return waypointValue.Entity.ToString();
    }
}

When we start our program, we want to fill it with some test data:

/// <summary>
/// 
/// </summary>
/// <param name="connection"></param>
public static void MakeDB(string connection)
{
    RallyDatabase db = new RallyDatabase(connection);

    //Temp
    db.DeleteDatabase();

    if (!db.DatabaseExists())
    {
        db.CreateDatabase();

        #region waypoint
        Waypoint w1 = new Waypoint();
        w1.Name = "VVV Breda";
        w1.GPSLatitude = 51.59380;
        w1.GPSLongitude = 4.77963;
        db.WaypointTable.InsertOnSubmit(w1);

        Waypoint w2 = new Waypoint();
        w2.Name = "Liefdeszuster";
        w2.GPSLatitude = 51.59307;
        w2.GPSLongitude = 4.77969;
        db.WaypointTable.InsertOnSubmit(w2);

        Waypoint w3 = new Waypoint();
        w3.Name = "Valkenberg";
        w3.GPSLatitude = 51.59250;
        w3.GPSLongitude = 4.77969;
        db.WaypointTable.InsertOnSubmit(w3);
        #endregion

        #region route
        Route testRoute1 = new Route();
        testRoute1.Name = "Kroegentocht";
        db.RouteTable.InsertOnSubmit(testRoute1);

        Route testRoute2 = new Route();
        testRoute2.Name = "Bezienswaardighedentocht";
        db.RouteTable.InsertOnSubmit(testRoute2);
        #endregion

        #region waypointlinks
        RouteWaypointLink routeWaypointLink1 = new RouteWaypointLink();
        routeWaypointLink1.Route = testRoute1;
        routeWaypointLink1.Waypoint = w1;
        routeWaypointLink1.WaypointIndex = 0;
        db.RouteLinkTable.InsertOnSubmit(routeWaypointLink1);

        RouteWaypointLink routeWaypointLink2 = new RouteWaypointLink();
        routeWaypointLink2.Route = testRoute1;
        routeWaypointLink2.Waypoint = w2;
        routeWaypointLink2.WaypointIndex = 1;
        db.RouteLinkTable.InsertOnSubmit(routeWaypointLink2);

        //Wut, why does it work when this is commented?
        RouteWaypointLink routeWaypointLink3 = new RouteWaypointLink();
        routeWaypointLink3.Route = testRoute1;
        routeWaypointLink3.Waypoint = w3;
        routeWaypointLink3.WaypointIndex = 2;
        db.RouteLinkTable.InsertOnSubmit(routeWaypointLink3);

        RouteWaypointLink routeWaypointLink4 = new RouteWaypointLink();
        routeWaypointLink4.Route = testRoute2;
        routeWaypointLink4.Waypoint = w1;
        routeWaypointLink4.WaypointIndex = 0;
        db.RouteLinkTable.InsertOnSubmit(routeWaypointLink4);

        RouteWaypointLink routeWaypointLink5 = new RouteWaypointLink();
        routeWaypointLink5.Route = testRoute2;
        routeWaypointLink5.Waypoint = w2;
        routeWaypointLink5.WaypointIndex = 1;
        db.RouteLinkTable.InsertOnSubmit(routeWaypointLink5);
        #endregion

        db.SubmitChanges();
    }
}

However, when we try to run this, we get an error pointing to db.SubmitChanges():

SqlCeException was unhandled - A foreign key value cannot be inserted because a corresponding primary key value does not exist. [ Foreign key constraint name = FK_RouteWaypointLink_Route ]

Now the weird thing: When I comment the last 3 inserts of RouteWaypointLink it works fine, so then it looks like this:

#region waypointlinks
RouteWaypointLink routeWaypointLink1 = new RouteWaypointLink();
routeWaypointLink1.Route = testRoute1;
routeWaypointLink1.Waypoint = w1;
routeWaypointLink1.WaypointIndex = 0;
db.RouteLinkTable.InsertOnSubmit(routeWaypointLink1);

RouteWaypointLink routeWaypointLink2 = new RouteWaypointLink();
routeWaypointLink2.Route = testRoute1;
routeWaypointLink2.Waypoint = w2;
routeWaypointLink2.WaypointIndex = 1;
db.RouteLinkTable.InsertOnSubmit(routeWaypointLink2);

//Wut, why does it work when this is commented?
//RouteWaypointLink routeWaypointLink3 = new RouteWaypointLink();
//routeWaypointLink3.Route = testRoute1;
//routeWaypointLink3.Waypoint = w3;
//routeWaypointLink3.WaypointIndex = 2;
//db.RouteLinkTable.InsertOnSubmit(routeWaypointLink3);

//RouteWaypointLink routeWaypointLink4 = new RouteWaypointLink();
//routeWaypointLink4.Route = testRoute2;
//routeWaypointLink4.Waypoint = w1;
//routeWaypointLink4.WaypointIndex = 0;
//db.RouteLinkTable.InsertOnSubmit(routeWaypointLink4);

//RouteWaypointLink routeWaypointLink5 = new RouteWaypointLink();
//routeWaypointLink5.Route = testRoute2;
//routeWaypointLink5.Waypoint = w2;
//routeWaypointLink5.WaypointIndex = 1;
//db.RouteLinkTable.InsertOnSubmit(routeWaypointLink5);
#endregion

db.SubmitChanges();

Isn’t it weird that it does work when 2 RouteWaypointLinks are being inserted, but not when we try to create 5?

We also saw the problem further in the program (we’re pretty far actually, but this is holding us back), when we tried to add a few RouteWaypointLinks.

Does anyone have a clue of what’s going on? We appreciate any help!

Yours,
Tregan

  • 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-17T13:06:59+00:00Added an answer on June 17, 2026 at 1:06 pm

    Hmm it seems I have fixed it by adding a few things

    private Nullable<int> idRoute;
    private Nullable<int> idWaypoint;
    
    [Column(Storage = "idRoute", DbType = "Int")]
    public int? IDRoute
    {
        get
        {
            return this.idRoute;
        }
        set
        {
            this.idRoute = value;
        }
    }
    
    [Column(Storage = "idWaypoint", DbType = "Int")]
    public int? IDWaypoint
    {
        get
        {
            return this.idWaypoint;
        }
        set
        {
            this.idWaypoint = value;
        }
    }
    

    Also, I changed the Associations to this:

    [Association(IsForeignKey = true, Storage = "routeValue", ThisKey="IDRoute")]
    public Route Route
    {
        get
        {
            return routeValue.Entity;
        }
        set
        {
            NotifyPropertyChanging("Route");
            routeValue.Entity = value;
            NotifyPropertyChanged("Route");
        }
    }
    
    [Association(IsForeignKey = true, Storage = "waypointValue", ThisKey="IDWaypoint")]
    public Waypoint Waypoint
    {
        get
        {
            return waypointValue.Entity;
        }
        set
        {
            NotifyPropertyChanging("Waypoint");
            waypointValue.Entity = value;
            NotifyPropertyChanged("Waypoint");
        }
    }
    

    It seems logical that I have to add columns that hold the primary keys from Route and Waypoint. But still, I don’t really understand why it would work when I added 2, but not when I added more.

    Well it’s fixed now so all is good.

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

Sidebar

Related Questions

I have this school project I'm making, where I need to make my code
I have a school project in which I have to implement a chat application,
I have the mission to make a small game for a school project. Pictures
I am trying to make an application as a school project and I MUST
I have been working on a project for school. Basically you have to make
I want to create an application to login to windows which would make use
For a school project, I have to make a table reservation system, I made
I'm trying to make a game in Java (school project) and I have the
For my school project, I am working on a database management application. It is
I have to make a hangman game for a school project and one of

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.