【问题标题】:Create Table On RunTime in mysql using C# and entity framework使用 C# 和实体框架在 mysql 中创建运行时表
【发布时间】:2018-07-03 08:07:40
【问题描述】:

我正在处理一项任务,我必须在单击按钮时使用现有数据源属性创建 mysql 表。下面是我的代码。

有什么帮助吗?

public BaseDto CreateTempTable(int dataSourceId, int profileId)
        {
            var dataSourceData = Unit.DataSourceRepository.Find(x => x.DataSourceId == dataSourceId).FirstOrDefault();
            var profileData = Unit.ProfileSettingRepository.Find(x => x.ProfileSettingId == profileId).FirstOrDefault();

            var tableName = dataSourceData.Name +"_"+ profileData.Name;

            var objectType = DynamicTypeBuilder.Createtype(dataSourceData);
            var listType = typeof(List<>);
            var constructedListType = listType.MakeGenericType(objectType);

            AddTableIntempDb(tableName, constructedListType);
            return Success();
        }

        private void AddTableIntempDb(string tableName, Type type)
        {
            //Code here
        }

【问题讨论】:

    标签: c# mysql entity-framework-6


    【解决方案1】:

    EF 是 ORM,而不是数据库设计工具。我只能找到 EF 不支持动态模式的语句。

    虽然有人找到work around it 的方法(请注意链接的博客文章是关于创建临时表)。请记住,您的源代码控制不会知道您在生产中动态创建的所有这些表。

    如果你真的想在运行时生成表,建议使用 ADO.NET。

    【讨论】:

      猜你喜欢
      • 2021-12-30
      • 2017-02-09
      • 2012-07-07
      • 2017-04-03
      • 2013-06-18
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      相关资源
      最近更新 更多