System.ArgumentException:不支持关键字:元数据

问题描述 投票:0回答:0

找了很久的解决方案,没有任何帮助,我不是很了解,所以可能是我没看懂。我将感谢ANY帮助。这是非常迫切需要的。

我的连接字符串是:

<add name="DBEntities" connectionString="metadata=res://*/DataFolder.ModelDB.csdl|res://*/DataFolder.ModelDB.ssdl|res://*/DataFolder.ModelDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-7HB074O\MSSQLSERVER2;initial catalog=KRS;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" /></connectionStrings></configuration>

出现这个错误的代码:

 public partial class AdminPage : Window
    {
        public AdminPage()
        {
            InitializeComponent();
            LoadPhotos();
        }

        private void LoadPhotos()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DBEntities"].ConnectionString;
            string selectQuery = "SELECT * FROM Photos";
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(selectQuery, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int id = reader.GetInt32(0);
                        string fileName = reader.GetString(1);
                        DateTime uploadDate = reader.GetDateTime(2);
                        int userId = reader.GetInt32(3);
                        string loginUser = reader.GetString(4);

                        dataGridPhotos.Items.Add(new PhotoData
                        {
                            Id = id,
                            FileName = fileName,
                            UploadDate = uploadDate,
                            UserId = userId,
                            LoginUser = loginUser
                        });
                    }
                }
                reader.Close();
            }
        }

我相信解决方案很简单,只是我的知识还不够,请帮忙。我准备好提供任何额外的数据。我的命运取决于明天的这份工作

c# sql entity-framework
© www.soinside.com 2019 - 2024. All rights reserved.