How to make Class for DataObjectAttribute visible in ObjectDataSourse in Web Application
here is a class code :
> [DataObjectAttribute] public class
> Report { publ开发者_开发问答ic this() {}
>
>
> [DataObjectMethodAttribute(DataObjectMethodType.Select,
> true)] public static
> GetAllEmployees() : DataTable {
> null }
>
>
> [DataObjectMethodAttribute(DataObjectMethodType.Delete,
> true)] public
> DeleteEmployeeByID(employeeID : int) :
> void {
> throw Exception("The value passed to the delete method is " +
> employeeID.ToString()); } }
but I still can't find where and how and what I must to config to access it ?
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod=" ?????????? ">
</asp:ObjectDataSource>
Web Application doesn't support App_Code so but I can use compiled Bin somehow, the question is how ?
text from this link only confused me more :(
thank you
You can work in work in source mode to configure the ObjectDataSource by I find it easier to use the smart tag from the control in design mode. If your data access dll is part of the project then you will be able to select it from the Choose A Business Object page of the Configure Data Source wizard(1st screen of the wizard). If your data access dll in in another project, you will need to add a reference to it.
EDIT:
Here is some of my working sample code to give you an idea as to what things should look like.
Data access layer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using Model;
namespace DAL
{
[DataObject(true)]
public class DepartmentDAL
{
[DataObjectMethod(DataObjectMethodType.Select, true)]
public IEnumerable<Model.Department> GetDepartments()
{
using(KDMEntities ctx = new KDMEntities())
{
return ctx.Departments.OrderBy(n => n.DepartmentName).ToList();
}
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public Department GetDepartmentByID(int deptID)
{
using (KDMEntities ctx = new KDMEntities())
{
// More similar code...
ASP.NET markup:
<asp:ObjectDataSource ID="odsDepartments" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetDepartments"
TypeName="DAL.DepartmentDAL">
</asp:ObjectDataSource>
<asp:GridView ID="gvDepartments" runat="server" DataSourceID="odsDepartments"
CssClass="datagrid" EnableViewState="true" AutoGenerateColumns="False" ShowFooter="true" Width="200px">
<Columns>
<asp:BoundField DataField="DepartmentName" HeaderText="Department"/>
<!-- Other columns -->
</Columns>
</asp:GridView>
Here's how the ObjectDataSource markup would look when using a custom type:
<asp:ObjectDataSource ID="odsDeptDetail" runat="server"
DataObjectTypeName="DAL.Department" InsertMethod="AddDepartment"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetDepartmentByID"
TypeName="DAL.DepartmentDAL" UpdateMethod="UpdateDepartment" >
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="deptID" QueryStringField="did" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
Department is my custom type, just a simple DTO really.
Since you are working with a web application, all you C# code will be compiled into a DLL located in the bin directory. When you deploy your code to a production server, all you need to do is copy the *.aspx files and the contents of your bin folder. This is a slight oversimplification as there could be other files to copy. Refer back the document you have on deploying web applications.
for class use [DataObject] attribute. this should help you.
in tag refer class using TypeName.
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod=" ?????????? " TypeName="class with complete namespace">
</asp:ObjectDataSource>
Clarify your question please.
It is possible to use an ObjectDataSource from Select/Delete/etc. methods out of a dll.
Try to use the wizard of the ObjectDataSource to set the context property of the ODS.
精彩评论