该论坛帖子有答案:
MetadataWorkspace workspace = new MetadataWorkspace( new string[] { "res://*/" }, new Assembly[] { Assembly.GetExecutingAssembly() }); using (SqlConnection sqlConnection = new SqlConnection(connectionString)) using (EntityConnection entityConnection = new EntityConnection(workspace, sqlConnection)) using (NorthwindEntities context = new NorthwindEntities(entityConnection)) { foreach (var product in context.Products) { Console.WriteLine(product.ProductName); } }
"res://*/"是EF连接字符串的一部分,用于描述xml映射文件的位置 - 在本例中是当前程序集中的嵌入资源.
该论坛帖子有答案:
MetadataWorkspace workspace = new MetadataWorkspace( new string[] { "res://*/" }, new Assembly[] { Assembly.GetExecutingAssembly() }); using (SqlConnection sqlConnection = new SqlConnection(connectionString)) using (EntityConnection entityConnection = new EntityConnection(workspace, sqlConnection)) using (NorthwindEntities context = new NorthwindEntities(entityConnection)) { foreach (var product in context.Products) { Console.WriteLine(product.ProductName); } }
"res://*/"是EF连接字符串的一部分,用于描述xml映射文件的位置 - 在本例中是当前程序集中的嵌入资源.