我是 Entity 框架的新手,我不明白为什么它给我一个 sql 语法错误,我认为使用 EFCore 的全部目的是处理 sql 语法并将所有 sql 查询抽象掉
这是我的模型:
class Block
{
public BlockHeader Header {get ;}
public List<Transaction> Transactions {get;}
public Block(List<Transaction> transactions, BlockHeader header)
{
Transactions= transactions;
Header=header;
}
public Block(){
}
}
public class BlockHeader
{
public byte[] Hash {get ;}
public byte[] PreviousHash { get; }
public DateTime timestamp { get; }
public int version{ get; }
public byte[] MerkleRoot{ get; }
public int SequenceNumber {get ; private set;}
public BlockHeader (byte[] previoushash,int sequencenumber,List<Transaction> transactions)
{
timestamp = DateTime.Now;
PreviousHash = previoushash;
version = 1;
SequenceNumber = sequencenumber;
MerkleRoot = ComputeMerkleRoot(transactions);
Hash = ComputeBlockHash();
}
这是我的数据库上下文类
class BlockchainDB : DbContext
{
public BlockchainDB()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL("server=localhost;database = Blockchain ;user = root ; password = password");
}
protected override void OnModelCreating(ModelBuilder builder){
builder.Entity<Block>(e => e.HasNoKey());
}
}
当我添加迁移时,它会成功添加,但是当我使用此命令更新数据库时
dotnet ef database update
它输出此错误:
Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE `Block` (
);
MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3