我有一个ASP.NET网站,其实体版本为4.0 DAL。我有几个页面,其中包含可以输入数据的文本框,以及用于查看和编辑该数据的gridview。我正在使用LINQ在其中一个页面的代码隐藏文件中编写插入逻辑。但是,我想实现一个BLL(业务逻辑层),以便我可以在几个地方使用这个代码,只在一个地方进行修改。无论如何,我需要为后面的代码中的特定表调用这些BLL函数,并且我想使用visual studio的GUI将它们附加到EntityDataSources。我已经设法创建一个单独的类文件来编写我的自定义逻辑,但当我使用GUI选择单独的更新,插入时,我看不到使BLL文件中的函数出现在EntityDataSources的下拉列表中,并删除功能。我用错误的属性装饰BLL中的函数吗?以下是我试图让它发挥作用。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyTestModel;
/// <summary>
/// Used as custom logic for running queries againts the Location table
/// </summary>
public class LocationBLL
{
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public IQueryable<RnLoc> viewLocation(string name)
{
MyTestEntities db = new MyTestEntities();
var L = (from a in db.Location
where a.Location == name
select a);
return L;
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, false)]
public bool InsertLocation(string location, string longName, string comments, bool active, bool current)
{
MyTestEntities db = new MyTestEntities();
Location L = new Location();
L.Location = location;
L.LongName = longName;
L.Comments = comments;
L.Active = active;
L.Current = current;
L.Edited = DateTime.Now;
L.Created = DateTime.Now;
L.EditedBy = "EIC";
L.CreatedBy = "EIC";
L.AreaID = 1;
db.AddToLocations(L);
db.SaveChanges();
return true;
}
}
答案 0 :(得分:0)
编辑:在实体框架中使用业务逻辑唯一不好的地方是,当您将像gridviews这样的东西绑定到调用业务逻辑的ObjectDataSources时,您必须禁用分页和排序。我发现,如果你想要分页和排序,你必须在业务逻辑中添加更多代码,以便对服务器端进行排序和分页,以及表适配器支持的客户端排序。相当痛苦,但可能更好的表现。