asp.net-mvc-3 – 如何在NHibernate 3.2中实现通用存储库模式和U
发布时间:2020-12-16 06:47:01 所属栏目:asp.Net 来源:网络整理
导读:我是NHibernate的新手,我正在尝试阻止Generic Repository Pattern和Unit of Work在ASP.NET MVC 3应用程序中使用.我用Google搜索了标题并找到了新的链接;但是所有这些对我来说都更加复杂.我使用StructureMap作为我的IOC.你能建议我一些链接或博客文章吗? 解
我是NHibernate的新手,我正在尝试阻止Generic Repository Pattern和Unit of Work在ASP.NET MVC 3应用程序中使用.我用Google搜索了标题并找到了新的链接;但是所有这些对我来说都更加复杂.我使用StructureMap作为我的IOC.你能建议我一些链接或博客文章吗?
解决方法
这里有几个要阅读的项目:
> Advantage of creating a generic repository vs. specific repository for each object? 我在最近的项目中使用的实现看起来像: public interface IRepository<T> { IEnumerable<T> GetAll(); T GetByID(int id); T GetByID(Guid key); void Save(T entity); void Delete(T entity); } public class Repository<T> : IRepository<T> { protected readonly ISession Session; public Repository(ISession session) { Session = session; } public IEnumerable<T> GetAll() { return Session.Query<T>(); } public T GetByID(int id) { return Session.Get<T>(id); } public T GetByID(Guid key) { return Session.Get<T>(key); } public void Save(T entity) { Session.Save(entity); Session.Flush(); } public void Delete(T entity) { Session.Delete(entity); Session.Flush(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – Visual Studio断点未被击中
- asp.net – 间歇性SQL连接错误
- asp.net-mvc – Web场中的nHibernate策略
- 如何使用ASP.NET和iframe对跨域的用户进行身份验证?
- IHttpAsyncHandler和ASP.NET“请求执行”计数器的问题
- asp.net-mvc – MVC应用程序部署; System.Data.SqlClient.S
- asp.net-mvc – 为什么@ Html.AntiForgeryToken()在同一个响
- asp.net-mvc – 被劫持的Umbraco HttpPost动作没有开火
- ASP.NET错误处理
- asp.net – 如何使用正则表达式将百分比验证到两位小数?
推荐文章
站长推荐
- entity-framework – 在新配置下在EF7中切换Prox
- asp.net-mvc-5 – MVC5中的域路由
- 如何将当前的asp.net usercontrols类名转换为c#上
- asp.net – SignalR(Hub)可以发送除信号制作者之
- asp.net-mvc – 如何在EditorTemplate中获取完全
- 不能在此路径中使用此配置节。如果在父级别上锁定
- ASP.net中的免费PDF查看器
- Global.asax中的ASP.NET MVC Application_Error处
- asp.net-mvc – 如何使用Durandal.js,mvc3部分视
- IIS 7.5应用程序初始化ASP.NET Web服务(预热),而
热点阅读