In .NET framework, we can load the .sdf file using System.Data.Linq.DataContext. But this is not available in .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);
}
}
Data for the application will be retrieved using DataContext in .NET Framework application, now in .NET Core, we could not work with loading .sdf files.
How can we use .sdf files in .NET Core?