Steps i am following to create my first BDC model in VS2010
1. Open VS and create an empty sharepoint project.
2. Create a folder "BDC", right click on it to add new item.
3. Select Bussiness data connectivity model and name it, "BDCModel" in my case.
Followed step mentioned in following posts.
http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=444
http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=433
One thing to me noted is Type of Return parameterz Type descriptor should be like this.
Name-of-project.ClassName,ModelName
- Set ReadOnly Property to Nothing for Create and Update Methods
- Add Settings.setting file
- Add ConnectionString in file
Add Following code in Service Class
-- ReadItem
public static TestClass ReadItem(int testID)
{
using (BCSLearningDataContext context = new BCSLearningDataContext(Settings.Default.ConnectionString))
{
TestClass testClass= context. TestClass .Where(e => e.TestID == testID ).FirstOrDefault();
return testClass ;
}
}
-- ReadList
public static IEnumerable< TestClass > ReadList()
{
using (BCSLearningDataContext context = new BCSLearningDataContext(Settings.Default.ConnectionString))
{
List< TestClass > dbTestClass= new List< TestClass >();
dbTestClass = context. TestClass .ToList< TestClass >();
return dbTestClass ;
}
}
-- Create
public static TestClass Create( TestClass newTestClass)
{
using (BCSLearningDataContext context = new BCSLearningDataContext(Settings.Default.ConnectionString))
{
context. TestClass.InsertOnSubmit( newTestClass );
try
{
context.SubmitChanges();
return newTestClass ;
}
catch (System.Data.Linq.ChangeConflictException ex)
{
string error = ex.Message;
throw ex;
}
}
}
-- Delete
public static void Delete(int testID)
{
using (BCSLearningDataContext context = new BCSLearningDataContext(Settings.Default.ConnectionString))
{
TestClass testClass= context.TestClass .Where(e => e.TestID == testID ).FirstOrDefault();
context. TestClass .DeleteOnSubmit( testClass );
try
{
context.SubmitChanges();
}
catch (System.Data.Linq.ChangeConflictException ex)
{
string error = ex.Message;
throw ex;
}
}
}
--Update
public static void Update(TestClass testClass)
{
using (BCSLearningDataContext context = new BCSLearningDataContext(Settings.Default.ConnectionString))
{
TestClass dbTestClass= context. TestClass.First(thisTest => thisTest.TestID.Equals( testClass.TestID ));
dbTestClass.Col1= testClass.Col1 ;
dbTestClass.Col2= dbTestClass.Col2;
...
try
{
context.SubmitChanges();
}
catch (System.Data.Linq.ChangeConflictException ex)
{
string error = ex.Message;
throw ex;
}
catch (Exception e)
{
throw e;
}
}
}
-- Creating a project to add custom web parts and display data of external list i have created yet.
Step 1. Added Empty sharepoint project.
Step 2. Added Feature.
Step 3.Added following MApped folders.
- Images
- Layouts
- CONTROLTEMPLATES
Step 4. Added new Folder WebParts.
Step 5 Added Visual web part
Added reference to BDCModel project.
Added Access list have columns of external list to bind data to gridview.
BCSLists > Lists > GenericList
-- A class having common functions used by all lists classed and generic functions
public abstract GenericList
{
protected string listName;
protected SPList list = null;
protected bool fromRootWeb = false;
public GenericList(string listName)
{
this.listName = listName;
}
public GenericList(string listName, bool fromRootweb)
{
this.listName = listName;
this.fromRootWeb = fromRootweb;
}
public string ListName
{
get { return listName; }
}
public SPList List
{
get
{
if (list == null)
{
try
{
list = fromRootWeb ? SPContext.Current.Site.RootWeb.Lists[this.ListName] : SPContext.Current.Web.Lists[this.ListName];
}
catch (Exception e)
{
throw new Exception("Unable to access list:" + this.listName);
}
}
return list;
}
}
}
> BCSLists > Lists > ListTestClass.cs
--1. Added reference to Microsoft.Sharepoint
-- Added a chil class "Columns" , having
-- Added all List Columns in this class.
(e.g) public const string BDCIdentity = "BDC Identity";
-- Added another class "TableColumns" Mapping DB table columns.
(e.g) public const string BDCIdentity = "BdcIdentity";
-- Added a constant mapped to List exact name
(e.g) public const string ListNameTestList = "TestList";
--
Creating a SharePoint 2010 Project
http://www.jones.bz/index.php/2010/05/15/developing-a-bdc-model-on-visual-studio-2010-for-sharepoint-foundation-2010-the-bdc-model-and-external-references/
http://www.jones.bz/index.php/2010/05/08/developing-a-bdc-model-on-visual-studio-2010-for-sharepoint-foundation-2010-install-create-and-deploy/
http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=433
http://fabiangwilliams.wordpress.com/2009/12/03/creating-a-sharepoint-2010-external-content-type-with-crud-methods-using-linq-and-a-sql-lob-system/
No comments:
Post a Comment