repository-pattern

Multiple database contexts when using repository pattern

谁说胖子不能爱 提交于 2019-12-05 08:31:46
问题 I am a bit lost right now... I've never seen this much divergent information regarding solution to the problem. But let us start from the beginning. I am using ASP.NET MVC with Repositories injected to Controllers, thanks to the Ninject. I have 2 simple Entities: Admin with a list of created blog entries and Entries with one virtual Admin field. Admin: public class Admin { [Key, ScaffoldColumn(false)] public int Id { get; set; } [Required(ErrorMessage = "Zły login.")] [StringLength(20),

If I expose IQueryable from my service layer, wouldn't the database calls be less if I need to grab information from multiple services?

陌路散爱 提交于 2019-12-05 08:09:58
问题 If I expose IQueryable from my service layer, wouldn't the database calls be less if I need to grab information from multiple services? For example, I'd like to display 2 separate lists on a page, Posts and Users . I have 2 separate services that provides a list of these. If both provides IQueryable, will they be joint in 1 database call? Each repository creates a context for itself. 回答1: It's best to think of an IQueryable<T> as a single query waiting to be run. So if you return 2 IQueryable

“Session is Closed!” - NHibernate

六眼飞鱼酱① 提交于 2019-12-05 07:56:50
This is in a web application environment: An initial request is able to successfully complete, however any additional requests return a "Session is Closed" response from the NHibernate framework. I'm using a HttpModule approach with the following code: public class MyHttpModule : IHttpModule { public void Init(HttpApplication context) { context.EndRequest += ApplicationEndRequest; context.BeginRequest += ApplicationBeginRequest; } public void ApplicationBeginRequest(object sender, EventArgs e) { CurrentSessionContext.Bind(SessionFactory.Instance.OpenSession()); } public void

Few things about Repository Pattern that I simply don't understand

独自空忆成欢 提交于 2019-12-05 07:55:05
I've read quite a few topic on what Repository is, but there are still few things bugging me. To my understanding only difference between Repository and traditional data access layers are Repository's query construction capabilities ( ie Query Object pattern ). But when reading the following definitions of a Repository Pattern , it seems we can still have Repository even if we don't implement Query Object pattern : a) From: Repositories are the single point where we hand off and fetch objects. It is also the boundary where communication with the storage starts and ends. I think above quote

Reusable Querying in Entity Framework WITHOUT Repository. How?

亡梦爱人 提交于 2019-12-05 05:13:10
Let me say, I have come to the conclusion (after a lot of trial) that Repository & Unit of Work when using Entity Framework is just wrong, wrong, wrong and this says why quite well. But I really hate on those embedded queries. Question is, where can I put them instead if I'm so against a repository, etc? (clean answers only please, examples much appreciated). I just nuked two projects containing my repositories, unit of work and interfaces with hundreds of files because the payback was nowhere to be seen. I think lots of people, myself included, just jumped on the Repository bandwagon because

Apply OrderBy with DbSet

只谈情不闲聊 提交于 2019-12-05 03:53:42
I am trying to implement pagination and sorting with generic repository. How to take primary key column as default order by column in DbSet ? DbSet = Context.Set<T>(); public IQueryable<T> GetAll(int pageNumber = 0, int pageSize = 10, string sortColumn = "") { return DbSet.OrderBy("how to use primary key column here").Skip(pageNumber * pageSize)Take(pageSize); } I have used these extension methods to achieve something similar: public static string GetKeyField(Type type) { var allProperties = type.GetProperties(); var keyProperty = allProperties.SingleOrDefault(p => p.IsDefined(typeof

EF repository pattern many to many insert

ε祈祈猫儿з 提交于 2019-12-05 02:59:19
问题 We have 2 tables: Table Authority: public class Authority { public int ID {get;set;} public string Name{get;set;} ... } Table Agents public class Agent { public int ID{get;set;} public int FirstName{get;set;} } And we have a relationship many-to-many between these two tables: public class AuthorityConfiguration : EntityTypeConfiguration<Authority> { public AuthorityConfiguration() : base() { HasKey(p => p.ID); HasMany(p => p.Agents).WithMany(a => a.Authorities).Map(mc => { mc.MapLeftKey(

NHibernate Repository

♀尐吖头ヾ 提交于 2019-12-05 02:55:43
问题 Does anybody has proper and simplified write up on NHibernate Repository? I've used Java, Hibernate, LCDS DataService Repositories with FlexBuilder (using rtmp channelling) and want to implement the exact fundamental with C#.NET. I've gone through lots of online documentation but nothing was reflecting the exact use like with FlexBuilder. If anybody has a small example application then do share. That would be much helpful. Regards Nitin 回答1: See these: Data Access With NHibernate Repository

How to use Order By in this MSDN example

不想你离开。 提交于 2019-12-05 02:26:17
I'm trying to figure out how to use this orderBy parameter. I am not sure what I am suppose to pass in. http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application public virtual IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") { IQueryable<TEntity> query = dbSet; if (filter != null) { query = query.Where(filter); } foreach (var includeProperty in includeProperties.Split (new char[

Onion Architecture - Service Layer Responsibility

偶尔善良 提交于 2019-12-05 01:34:32
问题 I am learning Onion Architecture by Jeffrey Palermo for more than 2 weeks now. I have created a test project by following this tutorial. While studying I came across this question on SO. According to accepted answer, one person nwang suggests that Methods like GetProductsByCategoryId should not be in Repository and one the other hand Dennis Traub suggests that it is the responsibility of the Repository. What I am doing is : I have a General Repository in Domain.Interface in which I have a