Runtime: How to use .sdf file in .NET Core?

Created on 29 Oct 2019  路  12Comments  路  Source: dotnet/runtime

In .NET framework, we can load the .sdf file using System.Data.Linq.DataContext. But this is not available in .NET Core.

How can we use .sdf files 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
{
get
{
return this.GetTable();
}
}
public System.Data.Linq.Table Customers
{
get
{
return this.GetTable();
}
}
public System.Data.Linq.Table Employees
{
get
{
return this.GetTable();
}
}
public System.Data.Linq.Table OrderDetails
{
get
{
return this.GetTable();
}
}
public System.Data.Linq.Table Orders
{
get
{
return this.GetTable();
}
}
public System.Data.Linq.Table Products
{
get
{
return this.GetTable();
}
}
public System.Data.Linq.Table Shippers
{
get
{
return this.GetTable();
}
}
public System.Data.Linq.Table Suppliers
{
get
{
return this.GetTable();
}
}
}
// 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);

}

}

}

area-System.Data

Most helpful comment

Yes, you can use SQL Server Compact from .NET Core, and pass the SqlCeConnection object to your LINQ to SQL DataContext constructor https://github.com/dotnet/corefx/issues/33897#issuecomment-536269132 (Not the string based constructor)

All 12 comments

Any update regarding this?

Any update regarding this??

Any Update?

CC. @danmosemsft, do you know who owns this?

If I understand right the question is really how to open an.sdf file (SQL Compact) file from within a.NET Core app. Not specific to Linq to SQL. That would be a question for the Data team. @cheenamalhotra ?

/cc @ErikEJ

AFAIK there's no support for SQL Server CE (officially deprecated in 2013) on .NET Core.

(FYI @danmosemsft @tannergooding I get notified of any issue labelled System.Data)

Yes, you can use SQL Server Compact from .NET Core, and pass the SqlCeConnection object to your LINQ to SQL DataContext constructor https://github.com/dotnet/corefx/issues/33897#issuecomment-536269132 (Not the string based constructor)

Am going to go ahead and close this as there's a solution, and nothing is actionable from our end.

@roji How do you configure a notification on Github label(s)?

We have an internal bot doing this, I'm not aware of a public solution... But I heard github are working on this feature!

Lucky you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

v0l picture v0l  路  3Comments

jzabroski picture jzabroski  路  3Comments

chunseoklee picture chunseoklee  路  3Comments

omajid picture omajid  路  3Comments

omariom picture omariom  路  3Comments