![]() |
VOOZH | about |
Microsoft Entity Framework serves as an object-relational mapping framework for working with data represented as objects. Although Visual Studio offers the ADO.NET Entity Data Model wizard to automatically generate the Entity Model, this model-first approach may present challenges when your data source undergoes changes or when you require greater control over entity operations. In this article, we will delve into the code-first approach for accessing SharePoint data through the CData ADO.NET Provider, providing you with more flexibility and control.
Accessing and integrating live data from SharePoint has never been easier with CData. Customers rely on CData connectivity to:
Most customers rely on CData solutions to integrate SharePoint data into their database or data warehouse, while others integrate their SharePoint data with preferred data tools, like Power BI, Tableau, or Excel.
For more information on how customers are solving problems with CData's SharePoint solutions, refer to our blog: Drivers in Focus: Collaboration Tools.
Modify the App.config file in the project to add a reference to the SharePoint Entity Framework 6 assembly and the connection string.
Set the URL property to the base SharePoint site or to a sub-site. This allows you to query any lists and other SharePoint entities defined for the site or sub-site.
The User and Password properties, under the Authentication section, must be set to valid SharePoint user credentials when using SharePoint On-Premise.
If you are connecting to SharePoint Online, set the SharePointEdition to SHAREPOINTONLINE along with the User and Password connection string properties. For more details on connecting to SharePoint Online, see the "Getting Started" chapter of the help documentation
<configuration> ... <connectionStrings> <add name="SharePointContext" connectionString="Offline=False;User=myuseraccount;Password=mypassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;SharePointEdition=SharePointOnPremise;" providerName="System.Data.CData.SharePoint" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.SharePoint" type="System.Data.CData.SharePoint.SharePointProviderServices, System.Data.CData.SharePoint.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class SharePointContext : DbContext {
public SharePointContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<SharePointContext>(null);
// To remove the plural names
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
[System.ComponentModel.DataAnnotations.Schema.Table("MyCustomList")]
public class MyCustomList {
[System.ComponentModel.DataAnnotations.Key]
public System.String Name { get; set; }
public System.String Revenue { get; set; }
}
public DbSet<MyCustomList> MyCustomList { set; get; }
SharePointContext context = new SharePointContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.MyCustomList select line;
Download a free trial of the SharePoint Data Provider to get started:
Download NowLearn more:
👁 SharePoint IconProvides .NET developers with the power to easily connect their Web, Desktop, and Mobile applications to data in SharePoint Server Lists, Contacts, Calendar, Links, Tasks, and more!