我必须在C#.Net 4.0中开发一个桌面窗口应用程序,它将在三个不同的数据库中运行,即.MS Access 2007及更高版本,Oracle 11G和SQL Server 2008.现在我想在我的应用程序中使用Entity Framework.这是我的应用程序使用EF的最佳选择吗?如果是,那么我如何使用Access数据库的实体框架?提前致谢.
在本次论坛在这里,有人提到,实体框架不能使用Access(Jet数据库- .mdb)中.然而,它似乎有A如对Jet数据库供应商在这里
这让我觉得Entity Framework唯一需要的就是在定义模型之前定义以下内容:
<connectionStrings>
<add name="ProductContext"
providerName="Microsoft.Jet.OLEDB.4.0"
connectionString="Source=C:\mydatabase.mdb;Jet OLEDB:Database
Password=MyDbPassword;"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
有没有人知道实体框架是否适用于Jet DB,我想在开始之前确保它确实如此,因为我的设计文档依赖于这个事实.
谢谢
有没有办法在使用C#访问时检索最新插入的guid?
我试过这个:创建了一个表,其中字段ID为autonumber,replicationID和字段名称varchar(250).
var command = myConnection.CreateCommand();
command.Connection.Open();
command.CommandText = "INSERT INTO Cars(Name) VALUES ('Pagani')";
command.ExecuteNonQuery();
command = context.Database.Connection.CreateCommand();
command.CommandText = "SELECT @@Identity";
Console.WriteLine(command.ExecuteScalar());
command.Connection.Close();
Run Code Online (Sandbox Code Playgroud)
我得到的问题是:
Console.WriteLine(command.ExecuteScalar());
Run Code Online (Sandbox Code Playgroud)
总是显示 0
编辑
要创建表,您可以在C#OleDb连接上使用此语句(我认为从MS Access查询不起作用)
CREATE TABLE [Cars] (
[Id] guid not null DEFAULT GenGUID(),
[Name] text null
);
ALTER TABLE [Cars] ADD CONSTRAINT [PK_Cars_6515ede4] PRIMARY KEY ([Id])
Run Code Online (Sandbox Code Playgroud) 从Oracle 12c开始,我们可以使用IDENTITY字段.
有没有一种方法来检索最后插入的标识(即select @@identity
或select LAST_INSERTED_ID()
等等)?
使用EF Core 2.0是否可以在2个表中映射一个实体?
EF6中与此类似(两个配置相同,它们只是示例)。
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(delegate(EntityMappingConfiguration<Student> studentConfig)
{
studentConfig.Properties(p => new { p.Id, p.StudentName });
studentConfig.ToTable("StudentInfo");
});
Action<EntityMappingConfiguration<Student>> studentMapping = m =>
{
m.Properties(p => new { p.Id, p.Height, p.Weight, p.Photo, p.DateOfBirth });
m.ToTable("StudentInfoDetail");
};
modelBuilder.Entity<Student>().Map(studentMapping);
}
Run Code Online (Sandbox Code Playgroud) 在EF6中,我可以检索迁移并逐步运行它.
有没有办法在EF Core中做类似的事情?
EF 6代码
public static void RunMigration(this DbContext context, DbMigration migration, string providerName, string manifest)
{
var prop = migration.GetType().GetProperty("Operations", BindingFlags.NonPublic | BindingFlags.Instance);
if (prop != null)
{
IEnumerable<MigrationOperation> operations = prop.GetValue(migration) as IEnumerable<MigrationOperation>;
MigrationSqlGenerator generator = (new DbMigrationsConfiguration()).GetSqlGenerator(providerName);
var statements = generator.Generate(operations, manifest);
foreach (MigrationStatement item in statements)
context.Database.ExecuteSqlCommand(item.Sql);
}
}
Run Code Online (Sandbox Code Playgroud) 我想将 SharpSVN 与 TortoiseSVN 的不同用户一起使用。
我使用 VisualSVN 作为服务器,我使用 https 连接到 VisualSVN。在 TortoiseSVN 中,网址是https://<myserver>
.
阅读周围我找到了一些可能的解决方案。
client.Authentication.ForceCredentials(user, password);
这最终会更改 TortoiseSVN 缓存,但实际上它是唯一对我有用的身份验证方法。
开头的方法
client.Authentication.Clear();
在这种情况下,当我使用客户端时,我收到错误
无法连接到 URL ' https://myserver '上的存储库
没有为 'svn.ssl.server' 凭据注册的提供程序