我正在学习EF6,我想和Firebird一起尝试。问题是我的生成器没有创建,只有表格。
public class Product
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int MajorVersion { get; set; }
public string PublicKey { get; set; }
public string privateKey { get; set; }
public virtual ICollection<ProductVersion> ProductVersions { get; set; }
}
执行此代码时:
using (LicenseContext licenseContext = new LicenseContext())
{
Product p = new Product { Name = "Test" };
licenseContext.Products.Add(p);
licenseContext.SaveChanges();
}
我收到以下错误:
An exception occurred while initializing the database. See the InnerException for details.
内部异常为:An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded or failed on the database server
仍在创建数据库,但没有Products表的生成器或触发器。 PrimaryKey已设置。
任何人都可以帮我吗?谢谢!
答案 0 :(得分:-1)
如果ProductId
是主键,则应该向您提供产品实例p.ProductId = 123;
或创建触发器和生成器
SET TERM;
CREATE OR ALTER TRIGGER "Product_BI" FOR "Product"
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
new.id = gen_id("sq_Product",1);
END
SET TERM;
COMMIT;