Code: Select all
[Serializable]
public class BaseEntity : Object
{
private Guid _RowGuid = Guid.NewGuid();
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[DescriptionAttribute("Record Ident")]
public Guid RowGuid // Using Binary(16) as Guid!
{
get
{
return _RowGuid;
}
set
{
_RowGuid = value;
NotifyPropertyChanged(() => RowGuid);
}
}
}
Code: Select all
[DescriptionAttribute("User"), Serializable]
public class User : BaseEntity
{
[Required, Description("UserName")]
public string UserName
{
get
{
return _UserName;
}
set
{
if (_UserName != value)
{
_UserName = value;
NotifyPropertyChanged(() => UserName);
}
}
}
}
Code: Select all
public class EntityContext : DbContext
{
public DbSet Users { get; set; }
}
Code: Select all
static void Main(string[] args)
{
EntityContext cnt = new EntityContext();
User _user = new User();
_user.RowGuid = Guid.NewGuid();
_user.UserName = "VPupkin";
cnt.Users.Add(_user);
cnt.SaveChanges(); // Exception - RowGuid has no default value!
}
Code: Select all
INSERT INTO Users(UserName)
VALUES (:p0)
;
SELECT RowGuid
FROM Users
WHERE RowGuid = last_insert_id() AND ROW_COUNT() = 1;