Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ到SQL-主键/外键设置_C#_Database_Linq_Windows Phone 8_Mvvm - Fatal编程技术网

C# LINQ到SQL-主键/外键设置

C# LINQ到SQL-主键/外键设置,c#,database,linq,windows-phone-8,mvvm,C#,Database,Linq,Windows Phone 8,Mvvm,我试图在我的应用程序中放一个相册,同时学习MVVM和LINQ以及C中的数据库交互。我对数据库有问题,特别是设置密钥 我的错误是: 其他信息:在类型“Album”上找不到键“PhotoID”的键成员“PhotoID”。键可能错误,或者“Album”上的字段或属性已更改名称 我改变了一些事情,希望能解决它,但那没有起作用。我认为,我的问题源于对EntitySet和EntityRef的理解不够透彻 编辑: 在相册关联中,指定AlbumID外键,但实体中不存在此类属性。您必须在照片实体中公开其公共属性

我试图在我的应用程序中放一个相册,同时学习MVVM和LINQ以及C中的数据库交互。我对数据库有问题,特别是设置密钥

我的错误是:

其他信息:在类型“Album”上找不到键“PhotoID”的键成员“PhotoID”。键可能错误,或者“Album”上的字段或属性已更改名称

我改变了一些事情,希望能解决它,但那没有起作用。我认为,我的问题源于对EntitySet和EntityRef的理解不够透彻

编辑:

在相册关联中,指定AlbumID外键,但实体中不存在此类属性。您必须在照片实体中公开其公共属性

有关协会的更多信息:


请在此发布相关代码。这是实体框架吗?这是基于以下内容的Windows Phone开发:LINQ到SQL?
[Table]
public class Album : BaseModel
{

    // Version column aids update performance.
    [Column(IsVersion = true)]
    private Binary _version;

    private int _albumID;

    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int AlbumID
    {
        get { return _albumID; }
        set
        {
            if (_albumID != value)
            {
                NotifyPropertyChanging();
                _albumID = value;
                NotifyPropertyChanged();
            }
        }
    }
private EntitySet<Photo> _photos;
    //Proxy Class used to get pickuplines related to the category
    //OtherKey = ForeignKey
    //ThisKey = PrimaryKey
    [Association(Storage = "_photos", OtherKey = "AlbumID", DeleteRule = "CASCADE", ThisKey = "PhotoID")]
    public EntitySet<Photo> Photos
    {
        get { return _photos; }
        set
        {
            this._photos.Assign(value);
        }
    }




[Table]
public class Photo : BaseModel
{

    // Version column aids update performance.
    [Column(IsVersion = true)]
    private Binary _version;

    private int _photoID;

    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int PhotoID
    {
        get { return _photoID; }
        set
        {
            if (_photoID != value)
            {
                NotifyPropertyChanging();
                _photoID = value;
                NotifyPropertyChanged();
            }
        }
    }
[Column]
    internal int _albumID;

    private EntityRef<Album> _album;
    // ForeignKey
    // Proxy Class for the PrimaryKey Class
    // ThisKey = ForeignKey
    // PtherKey = PrimaryKey
    [Association(Storage = "_album", ThisKey = "AlbumID", DeleteRule = "CASCADE", OtherKey = "PhotoID", IsForeignKey = true)]
    public Album Album
    {
        get { return _album.Entity; }
        set
        {
            NotifyPropertyChanging();
            _album.Entity = value;
            if (value != null)
            {
                _albumID = value.AlbumID;
            }
            NotifyPropertyChanged();
        }
    }
private int _albumID;

[Column(CanBeNull = false)]
public int AlbumID
{
    get { return _albumID; }
    set
    {
        if (_albumID != value)
        {
            NotifyPropertyChanging();
            _albumID = value;
            NotifyPropertyChanged();
        }
    }
}