InsertOnSubmit - NullReferenceException
Posted
by
Jackie Chou
on Stack Overflow
See other posts from Stack Overflow
or by Jackie Chou
Published on 2012-11-03T16:58:19Z
Indexed on
2012/11/03
17:00 UTC
Read the original article
Hit count: 458
I have 2 Model
AccountEntity
[Table(Name = "Account")]
public class AccountEntity
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
public int id { get; set; }
[Column(CanBeNull = false, Name = "email")]
public string email { get; set; }
[Column(CanBeNull = false, Name = "pwd")]
public string pwd { get; set; }
[Column(CanBeNull = false, Name = "row_guid")]
public Guid guid { get; set; }
private EntitySet<DetailsEntity> details_id { get; set; }
[Association(Storage = "details_id", OtherKey = "id", ThisKey = "id")]
public ICollection<DetailsEntity> detailsCollection { get; set; }
}
DetailsEntity
[Table(Name = "Details")]
public class DetailsEntity
{
public DetailsEntity(AccountEntity a) {
this.Account = a;
}
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "int")]
public int id { get; set; }
private EntityRef<AccountEntity> _account = new EntityRef<AccountEntity>();
[Association(IsForeignKey = true, Storage = "_account", ThisKey = "id")]
public AccountEntity Account { get; set; }
}
Main
using (Database db = new Database())
{
AccountEntity a = new AccountEntity();
a.email = "hahaha";
a.pwd = "13212312";
a.guid = Guid.NewGuid();
db.Account.InsertOnSubmit(a);
db.SubmitChanges();
}
that has relationhip AccountEntity <- DetailsEntity (1-n)
when i'm trying to insert a record exception throws NullReferenceException
cause: by EntitySet null
please help me make it insert
© Stack Overflow or respective owner