0

我正在尝试在我的 Windows Phone 7 应用程序中创建本地 SQL Server CE 数据库。

这是 Employee 类,它包含字段的属性,这些字段是用于构建数据库的表和列

我想要:

  • EmployeeID将from的类型更改intuniqueidentifier
  • 使它成为主键,但我不知道如何。

错误:

uniqueidentifier无法识别(我是否缺少图书馆参考资料?)

namespace F5debugWp7LocalDatabase
{
[Table]
public class Employee
{
    public int EmployeeID
    {
        get;
        set;
    }
    [Column(CanBeNull = false)]
    public string EmployeeName
    {
        get;
        set;
    }
    [Column(CanBeNull = false)]
    public string EmployeeAge
    {
        get;
        set;
    }
}
}    
4

2 回答 2

1

使用SQL 字段的System.Guid类型。uniqueidentifier

要使其成为主键,请添加IsPrimaryKey=true到 ColumnAttribute 定义。

于 2012-05-17T16:22:55.550 回答
0

To create my local SQL CE database on windows phone 7 i used LinqToSQL, i generated the database in a separate project then i added it to my Windows Phone project and commented out the two constructors which are not supported in the Windows Phone 7 environment and it works like a charm.

But maybe this will help you too, my ID definitions look like this.

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", AutoSync=AutoSync.OnInsert, DbType="INT NOT NULL Identity", IsPrimaryKey=true, IsDbGenerated=true)]
于 2012-05-17T16:23:44.240 回答