microsoftechies.files.wordpress.com€¦ · web viewsharepoint 2010 bcs. open vs 2010file...
TRANSCRIPT
SharePoint 2010 BCS
Open VS 2010File NewProjectSharePoint 2010
Select Business Data Connectivity model
Enter Name
Select farm solution
Default methods
ReadItem, ReadList
How to add new method
Click on “Add a Method”
Select “Create updater Method”
TO update the list you need identifier and values.
Now I am going to add new parameter
By clicking on <Add a parameter> under Parameters of Update method
Change the name of parameter as idntifier1, see above screen
Copy Existing identifier data type to new one.
Paste on new method @identifier
Rename below one to “Identifier1”
Set pre-update field=true
Click on solution explorer
Open “Entity1Service.cs” file
Add below code
public static Dictionary<string, Entity1> d = new Dictionary<string, Entity1>() { {"0",new Entity1(){Identifier1="0",Message="MS"}}, {"1",new Entity1(){Identifier1="1",Message="Welcome"}} };
Now the code will looks like this
using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace MyBDC.BdcModel1{ /// <summary> /// All the methods for retrieving, updating and deleting data are implemented in this class file.
/// The samples below show the finder and specific finder method for Entity1. /// </summary> public class Entity1Service { public static Dictionary<string, Entity1> d = new Dictionary<string, Entity1>() { {"0",new Entity1(){Identifier1="0",Message="MS"}}, {"1",new Entity1(){Identifier1="1",Message="Welcome"}} };
/// <summary> /// This is a sample specific finder method for Entity1. /// If you want to delete or rename the method think about changing the xml in the BDC model file as well. /// </summary> /// <param name="id"></param> /// <returns>Entity1</returns> public static Entity1 ReadItem(string id) { //TODO: This is just a sample. Replace this simple sample with valid code. Entity1 entity1 = new Entity1(); entity1.Identifier1 = id; entity1.Message = "Hello World"; return entity1; } /// <summary> /// This is a sample finder method for Entity1. /// If you want to delete or rename the method think about changing the xml in the BDC model file as well. /// </summary> /// <returns>IEnumerable of Entities</returns> public static IEnumerable<Entity1> ReadList() { //TODO: This is just a sample. Replace this simple sample with valid code. Entity1[] entityList = new Entity1[1]; Entity1 entity1 = new Entity1(); entity1.Identifier1 = "0"; entity1.Message = "Hello World"; entityList[0] = entity1; return entityList; }
public static void Update(Entity1 entity1, string Identifier1) { throw new System.NotImplementedException(); } }}
Now change readitem method code
return new Entity1() { Identifier1 = d[id].Identifier1, Message = d[id].Message };
So readitem method code will be.
public static Entity1 ReadItem(string id) { ////TODO: This is just a sample. Replace this simple sample with valid code. //Entity1 entity1 = new Entity1(); //entity1.Identifier1 = id; //entity1.Message = "Hello World"; //return entity1;
return new Entity1() { Identifier1 = d[id].Identifier1, Message = d[id].Message }; }
Now change IEnumerableNow the code for IEnumerable is….
public static IEnumerable<Entity1> ReadList() { ////TODO: This is just a sample. Replace this simple sample with valid code. //Entity1[] entityList = new Entity1[1]; //Entity1 entity1 = new Entity1(); //entity1.Identifier1 = "0"; //entity1.Message = "Hello World"; //entityList[0] = entity1; //return entityList; return d.Values; }Now change “Update” method code..public static void Update(Entity1 entity1, string Identifier1) { //throw new System.NotImplementedException(); d[Identifier1].Message = entity1.Message; d[Identifier1].Identifier1 = entity1.Identifier1; }Final code of: Entity1Service.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace MyBDC.BdcModel1{ /// <summary> /// All the methods for retrieving, updating and deleting data are implemented in this class file. /// The samples below show the finder and specific finder method for Entity1. /// </summary> public class Entity1Service { public static Dictionary<string, Entity1> d = new Dictionary<string, Entity1>() { {"0",new Entity1(){Identifier1="0",Message="MS"}},
{"1",new Entity1(){Identifier1="1",Message="Welcome"}} };
/// <summary> /// This is a sample specific finder method for Entity1. /// If you want to delete or rename the method think about changing the xml in the BDC model file as well. /// </summary> /// <param name="id"></param> /// <returns>Entity1</returns> public static Entity1 ReadItem(string id) { ////TODO: This is just a sample. Replace this simple sample with valid code. //Entity1 entity1 = new Entity1(); //entity1.Identifier1 = id; //entity1.Message = "Hello World"; //return entity1;
return new Entity1() { Identifier1 = d[id].Identifier1, Message = d[id].Message }; } /// <summary> /// This is a sample finder method for Entity1. /// If you want to delete or rename the method think about changing the xml in the BDC model file as well. /// </summary> /// <returns>IEnumerable of Entities</returns> public static IEnumerable<Entity1> ReadList() { ////TODO: This is just a sample. Replace this simple sample with valid code. //Entity1[] entityList = new Entity1[1]; //Entity1 entity1 = new Entity1(); //entity1.Identifier1 = "0"; //entity1.Message = "Hello World"; //entityList[0] = entity1; //return entityList; return d.Values; }
public static void Update(Entity1 entity1, string Identifier1) { //throw new System.NotImplementedException(); d[Identifier1].Message = entity1.Message; d[Identifier1].Identifier1 = entity1.Identifier1; } }}
Deploy the solution
Why we are doing IIS reset when deploying solution:Ans: If you have any existing solution with name, it will remove and add into GAC.
Open SharePoint SiteClick on “All Site Content”Click on “Create”Select ListExternal ListClick on Create, Enter name of list and description of list.In the “Data Source Configuration” Click on ”Select external Content type”You will get prompt, where you can select your BDC Model.
Click on Create
My Data is available here
I can update these rows also.
So here what I am trying to say is:
public static Dictionary<string, Entity1> d = new Dictionary<string, Entity1>() { {"0",new Entity1(){Identifier1="0",Message="MS"}}, {"1",new Entity1(){Identifier1="1",Message="Welcome"}} };
In the above method I can pull some data from SQL and oracle…
In central admin we can see BDC models…
Central Administration -->Manage service applications (under Application Management)
Click on Business Data Connectivity Service
You can find bdc models here