Closed
Description
#if DEBUG
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using MySql.Data.MySqlClient;
using MySqlConnector;
namespace WCloud.Framework.Database.EntityFrameworkCore.MySQL
{
class User
{
public string Id { get; set; }
}
class UserMapper : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.ToTable("xx");
builder.HasKey(x => x.Id);
builder.Property(x => x.Id).HasMaxLength(100);
}
}
class test
{
test()
{
new MySqlConnectionStringBuilder().ToString();
var model = new ModelBuilder(new ConventionSet()).ApplyConfiguration(new UserMapper()).FinalizeModel();
new ModelBuilder(new Model()).ApplyConfigurationsFromAssembly(null).FinalizeModel();
new DbContext(null).Model.GetEntityTypes();
foreach (var e in model.GetEntityTypes())
{
e.GetTableName();
foreach (var p in e.GetProperties())
{
p.GetMaxLength();
p.GetColumnName();
p.GetColumnType();
}
}
}
}
}
#endif
通过这种方式可以获取ef的mapping,这样是否可以转换成freesql的mapping data。从而实现一套配置,同时使用ef和freesql
(原本想是否可以在dbcontext上扩展出iselect iinsert iupdate,但是发现两个框架设计理念差异比较大,需要为api妥协很多)
Metadata
Metadata
Assignees
Labels
No labels