我正在尝试使用Entity Framework Code First在表中创建'time(7)'列.这是我的实体:
public class ShiftDetail
{
public long Id { get; set; }
[Required]
public int DayOfWeek { get; set; }
[Required]
[Column(TypeName="time")]
public DateTime StartTime { get; set; }
[Required]
[Column(TypeName = "time")]
public DateTime EndTime { get; set; }
public long ShiftId { get; set; }
public virtual Shift Shift { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我正在尝试将StartTime和EndTime列的数据库类型设置为"time",但是我收到此错误:
(112,12):错误2019:指定的成员映射无效.类型'ShiftDetail'中成员'StartTime'的类型'Edm.DateTime [Nullable = False,DefaultValue =,Precision =]'与'SqlServer.time [Nullable = False,DefaultValue =,Precision = 7]'不兼容'CodeFirstDatabaseSchema.ShiftDetail'类型中的成员'StartTime'.
我也试过TypeName ="time(7)"但我得到了另一个错误:
(104,6):错误0040:类型时间(7)未使用命名空间或别名限定.只有原始类型可以无限制地使用.
如何创建包含代码的时间列?(最好没有流畅的API)
提前致谢.
.net entity-framework code-first entity-framework-4 ef-code-first
我很难解决一个愚蠢的映射问题.基本上发生的事情是我在sql db表中有一个字段,它是一个varbinary用于安全性(加密和解密).所有这些东西都很好,但似乎edmx看到该表中的字段为一个字符串,我认为应该看到它只是一个二进制字符串.这是我收到的错误消息.
Schema specified is not valid. Errors:
ReadModel.Model.msl(836,12): error 2019: Member Mapping specified is not valid. The type
'Edm.String [Nullable=True,DefaultValue=,MaxLength=256,Unicode=,FixedLength=False]' of
member 'field-in-question' in type 'Lib.ReadModel.TableName' is not compatable with
'SqlServer.varbinary' [Nullable=True,DefaultValue=,MaxLength=256,FixedLength=False]'
of member 'field-in-question' in type 'Model.Store.TableName'.
Run Code Online (Sandbox Code Playgroud)
有没有人有这样的问题?也许我有一些东西可以忽略?也许能够指出我正确的方向?我在寻找解决问题的信息方面遇到了问题而且处于亏损状态.
我一直在努力使用 VS 代码设置实体框架,使用本教程: https:
//www.learnentityframeworkcore.com/walkthroughs/aspnetcore-application
但是,在执行迁移时,我遇到了这个特定错误:关键字不受支持:到目前为止,
我找到的最好的帮助参考是这个 stackoverflow,但是,由于我迄今为止一直遵循的设置,所有解决方案似乎都不起作用
C# 实体框架:不支持关键字:'port '
这似乎是给我带来麻烦的代码:
using Microsoft.EntityFrameworkCore;
namespace EFPrac
{
public class EFCoreWebDemoContext : DbContext
{
public DbSet<Book> Books { get; set; }
public DbSet<Author> Authors { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string connectionString = "server=localhost;port=3306;database=EFpractice;uid=root,Pwd=****";
optionsBuilder.UseSqlServer(connectionString);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用 MySQL EF 6(MySQL.Data.Entity 包)连接到 MySQL DB。如果我使用构造函数 connectionStringName ,一切都可以:base("MyContext")。但如果我直接使用connectionString,它不起作用:base("server=localhost;port=3306;database=wordpress;uid=root")。应用程序引发错误System.ArgumentException: Keyword not supported: 'port'.
我的项目需要直接使用连接字符串。有谁知道如何修理它?谢谢
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class MyContext : DbContext
{
static MyContext()
{
Database.SetInitializer<MyContext>(null);
}
public MyContext()
//:base("server=localhost;port=3306;database=wordpress;uid=root;password=") not work
:base("MyContext") // it worked if using connectionStringName
{
}
}
Run Code Online (Sandbox Code Playgroud)