I am using Xamarin and sqlite.Net and sqlite.Net extensions.
I generated my model from visual studio.
My problem is that I want to add some attributes to these generated classes: ForeignKey, OneToOne, etc...
My generated class looks like this:
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");
}
}
}
And my extension:
[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; }
}
When I set [OneToOne] tag directly in the generated class I can create my tables else if its only in the partial class it does not work and throw an exception that say it does not know about "Happening"... Any idea on how to add attribute to existing property in extension in c#?
EDIT: It is SQLite which throw the exception not the compiler. Connection = new SQLiteConnection(platForm, filePath); SQLiteService.Instance._dbPath = filePath; Debug.WriteLine("[SQLITE] FilePath: {0}", filePath);
Connection.CreateTable<Happening>();
Connection.CreateTable<Zone>();
Connection.CreateTable<DeviceConfiguration>();
Aucun commentaire:
Enregistrer un commentaire