我正在使用Xamarin和sqlite.Net以及sqlite.Net扩展。
我从visual studio中生成了我的模型。
我的问题是我想为这些生成的类添加一些属性:ForeignKey,OneToOne等......
我生成的类看起来像这样:
public partial class Zone : object, System.ComponentModel.INotifyPropertyChanged {
private AccueilInvites.VVIPService.Happening HappeningField;
private int HappeningIdField;
private int LocalIdField;
private string NameField;
[System.Runtime.Serialization.DataMemberAttribute()]
public AccueilInvites.VVIPService.Happening Happening {
get {
return this.HappeningField;
}
set {
if ((object.ReferenceEquals(this.HappeningField, value) != true)) {
this.HappeningField = value;
this.RaisePropertyChanged("Happening");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int HappeningId {
get {
return this.HappeningIdField;
}
set {
if ((this.HappeningIdField.Equals(value) != true)) {
this.HappeningIdField = value;
this.RaisePropertyChanged("HappeningId");
}
}
}
我的扩展名:
[MetadataType(typeof(Zone_MetaData))]
public partial class Zone
{
[PrimaryKey]
public int ai_id { get; set; }
}
public class Zone_MetaData
{
[OneToOne]
[System.Runtime.Serialization.DataMemberAttribute()]
public AccueilInvites.VVIPService.Happening Happening
{
get; set;
}
[ForeignKey(typeof(Happening))]
[System.Runtime.Serialization.DataMemberAttribute()]
public int HappeningId { get; set; }
}
当我在生成的类中直接设置[OneToOne]标记时,我可以创建我的表,如果它只在部分类中它不起作用并抛出一个异常,说它不知道“发生”...任何关于如何在c#中添加属性到扩展中现有属性的想法
编辑:SQLite抛出异常而不是编译器。 Connection = new SQLiteConnection(platForm,filePath); SQLiteService.Instance._dbPath = filePath; Debug.WriteLine(“[SQLITE] FilePath:{0}”,filePath); Connection.CreateTable<Happening>();
Connection.CreateTable<Zone>();
Connection.CreateTable<DeviceConfiguration>();