【发布时间】:2019-10-25 06:08:12
【问题描述】:
在 .NET 框架中,我们可以使用 System.Data.Linq.DataContext 加载 .sdf 文件。但这在 .NET Core
中不可用public partial class Northwind : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
....
public Northwind(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
.....
public System.Data.Linq.Table<Categories> Categories
{
get
{
return this.GetTable<Categories>();
}
}
public System.Data.Linq.Table<Customers> Customers
{
get
{
return this.GetTable<Customers>();
}
}
public System.Data.Linq.Table<Employees> Employees
{
get
{
return this.GetTable<Employees>();
}
}
public System.Data.Linq.Table<OrderDetails> OrderDetails
{
get
{
return this.GetTable<OrderDetails>();
}
}
public System.Data.Linq.Table<Orders> Orders
{
get
{
return this.GetTable<Orders>();
}
}
public System.Data.Linq.Table<Products> Products
{
get
{
return this.GetTable<Products>();
}
}
}
// Getting Data
private void PopulateData()
{
Random r = new Random();
Northwind north = new Northwind(string.Format(@"Data Source= {0}",
FindFile("Northwind.sdf")));
foreach (OrderDetails orderDet in north.OrderDetails.Take(50))
{
OrderInfo orderInfo = new OrderInfo();
orderInfo.OrderID = orderDet.OrderID;
orderInfo.CustomerID = orderDet.Orders.CustomerID;
orderInfo.ProductName = orderDet.Products.ProductName;
orderInfo.UnitPrice = (double)orderDet.UnitPrice;
orderInfo.OrderDate = (DateTime)orderDet.Orders.OrderDate;
orderInfo.DeliveryDelay = (DateTime)orderDet.Orders.ShippedDate -
orderInfo.OrderDate;
orderInfo.Quantity = orderDet.Quantity;
orderInfo.ContactNumber = r.Next(999111234, 999111239).ToString();
orderInfo.ShipAddress = orderDet.Orders.ShipAddress;
_orderList.Add(orderInfo);
}
}
将使用 .NET Framework 应用程序中的 DataContext 检索应用程序的数据,现在在 .NET Core 中,我们无法加载 .sdf 文件。
我们如何在 .NET Core 中使用 .sdf 文件?
【问题讨论】:
-
你有 .net 框架端的示例代码吗?可以分享一下吗?
-
使用
.sdf数据库文件的SQL Server Compact Edition (CE) 早已停产。我非常怀疑 MS 是否会在 .NET Core 中支持它...... -
System.Data.Linq.DataContext是 LINQ To SQL 的一部分,自 Entity Framework 出现以来,它本身就是生命支持。到目前为止,它很少使用。在任何情况下,它都只是一个“示例”提供程序,而不是功能齐全的 ORM。将其移植到 .NET Core 的可能性很小,至少微软不会
标签: c# .net-core sql-server-ce