Entity Service is Independent Service--àworks for any Provider:
Ex: SqlClient,OracleClient,OledbClient….ect.
We know that Entity Framework Designer by default generates
every member as DataMemberAttributes. So Every member is serializable.*****(using DataContract
Serializer);
And
Now we can create a
service( Independent Service). Which work
for any Underlaying Provider(underlaying database). Because of Conceptual
model.
Same service works
for ----MS-Sql Server, OracleClient, OledbClient,MySql…ect.
then
Now add –new Item---WCF Service—EntityService-àEntityService.cs and IEntityService.cs
at
IEntityService:
[ServiceContract]
public interface IEntityService
{
[OperationContract]
[FaultContract(typeof(CustomFaultMsg))]
Employees
GetCategory(int Empid);
}
[DataContract]
public struct CustomFaultMsg
{
[DataMember]
public string
MyCustomErrMsg { get; set;
}
}
better to write as single northwind service instance for multiple clients at ServiceImplementation: more
readable/clear
public Product
GetCategory(int ProID)
{
NorthwindEntities context = EntityService.Instance();
IQueryable<Product>
productsupplier = context.Products.Where<Product>(t
=> t.ProductID == ProID);
IEnumerator<Product>
iers
=productsupplier.GetEnumerator();
while (iers.MoveNext())
{
product = new Product();
product.ProductName = iers.Current.ProductName;
product.QuantityPerUnit = iers.Current.QuantityPerUnit;
// *****If LazyLoadingisEnable=ture
product.Supplier = new Supplier { CompanyName = iers.Current.Supplier.CompanyName
};
product.Category = new Category { CategoryName =
iers.Current.Category.CategoryName }; //*******
return product;
}
return product;
}
app.config
CommandBehavior.SequentialAccess
takes the data from the database as per alphabithacal order :
so becare about oder of database columns: datarader read in database:
now at service implementation all classes are Provider independent classes.
so we can say my service is Independent client Service. because of EntityCommand,EntityConnection, EntityDataRader.....ect.
at Client
Reference : http://msdn.microsoft.com/en-us/library/bb738684.aspx
No comments:
Post a Comment