我有一个具有实体版本 4.0 DAL 的 ASP.NET 网站。我有几个页面,其中包含可以输入数据的文本框,以及用于查看和编辑该数据的 gridview。我正在使用 LINQ 在其中一页的代码隐藏文件中编写插入逻辑。但是,我想实现一个 BLL(业务逻辑层),以便我可以在多个地方使用此代码,并且只在一个地方进行修改。无论如何,我需要在后面的代码中为特定表调用这些 BLL 函数,并且我想使用 Visual Studio 的 GUI 将它们附加到 EntityDataSources。我已经设法创建了一个单独的类文件来编写我的自定义逻辑,但是当我使用 GUI 选择单独的更新、插入、和删除功能。我是否用错误的属性装饰了 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;
}
}