Architecture :: MVC Linq To Sql Repository And Search
Apr 15, 2010
I need some guidance for an application I am working on. I have searched the web and the forum and found parts that answer my questions but I want to do this correctly. My solution uses LINQ to SQL to model the db and I have a repository that is querying my db everytime a controller needs to get some data for the view. I am initially anticipating a maximum of only about a few hundreds hits per day (if that). The website is a directory, with listings and requires a search functionality.
1. What options should I consider to avoid having my repository query the db everytime
2. The site contains a 'search' option, how can I implement this against my repository?
I guess I'm really looking for someone to point me in the right direction. So far I've looked at 'caching' the LINQ to SQL model and Lucene.NET but both seem overkill or am I missing the point?
View 3 Replies
Similar Messages:
Jul 8, 2010
This is possibly the worst kind of religious debate -- a religious debate with practical consequences. But it's one that needs to be had, and I can't seem to fit it in my tiny head. Here are the pros and cons of the pattern as I know them:
Pros:
-Encourages DRY (don't repeat yourself) design in that identical queries are written only once per set of query conditions
-Facilitates unit testing by allowing itself to be abstracted into an interface
-Creates an opportunity for business-level validation
Cons:
-Breaks DRY philosophy in that you're generally repeating your database schema
-In a sense breaks separation of concerns, because the query concerns of the controller and view frequently become the concerns of whoever is maintaining the repository
-Determining what should be a repository and what should be returned as a raw associated ORM entity becomes an ambiguous art
To me it seems like all this stuff should be done at the ORM level, but Entity Framework has much fewer hooks than Linq to Sql does, yet Entity Framework tends to be regarded as being more robust, so it seems that this is by design, and that the designers of EF are in fact encouraging another layer. Are there any tools or anything that I could be using for this? Am I missing something?
View 6 Replies
Dec 21, 2010
I am currently using the 3-tier Repository pattern in my application. Actually it's the first time for me to implement a design pattern at all! i used to put all my code in the so called now presentation layer.
i want to implement data validation, for example, password should not be more than 10 characters and have to contain special characters. Should i put this code in the data access layer? but my data access layer contains methods that take the DTO as a parameter for example
[Code]....
and the same is for other CRUD operations (DELETE and UPDATE), so implementing such validation on the DAL would make me duplicate the code in each and every method that accepts the DataObject as a paramter. Same holds for the business logic layer where i am using it as a proxy between the presentation and the data access layers.
Eventually it has to use the same Data Objects as parameters. This only leaves me with one option which is to do the validation on the Data Object part. But i think this is not the essence of the respository pattern which states that the Data object class should only be a "container" class with no behavior.
View 1 Replies
Sep 26, 2010
I've been reading recently about EF4, and how to build an architecture for asp.net web forms application using it.
I explored using POCOs (self tracking entities), with WCF, but found out that my application will be deployed on a single box (i.e. one tier), so I started reading about logical separation of layers, and came up with the following solution:
DAL layer that contains EDMX model and EF APIs, and also generated context object.Entities DLL that holds all generated POCO entities using ADO.NET POCO entity generator. (for persistence ignorance, and decoupling entities from DAL).Business layer that contains a façade for each related group of business functions, the façade will be aware of and using DAL layer. And in each function, it will initiate context and uses different entities to carry out specific job (i.e. function).UI layer that only calls the business layer façade classes. With no awareness of DAL, but it will be aware of entities (i.e. using entities DLL), as the business layer will return results basically as entity collections.
I want to know what you think about this architecture.
I also read about an architecture that uses repository and unit of work patterns, but what I understand that context object is already implementing a UOF pattern, and also object sets are implementing repository pattern (correct me if I'm wrong), so the only advantage of using additional abstraction over them is to make the business layer communicates to my classes, not EF classes, and this is good only if the DAL strategy might change (i.e. by using another tool other than EF, which is not my plan).
View 8 Replies
May 31, 2010
I read some article about unitOfwork and repository but i'm still confused about how they interact, and how to use them in the right way.
I'm using an addressbook project to practise on patterns (even if , likely, patterns are not usefull) without any ORM framework for persistence.
My domain objects are (at now) : AddressBook (acts as an application controller), Contact (contains information about each contact in the address book), ContactGroup (mantain collections of contact).
Should i have to use distinct repository object for contact ad contactgroup?
I thought to use a UnitOfWork for the operation about the adding/removing contact to group : the user can add existing contact to a group, create a new contact while adding it to the group or remove contact from group.
View 1 Replies
Jan 26, 2011
Just wondering, in an ASP.NET MVC3 environnement with entity framework. Should the Unit of Work point to the service layer or the repository (and then the repository point to the service layer) ?
Ive saw two example:
* One where the unit of work and repository both have an instance to the service layer..
Link: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable
Doesn't use a service layer but its obvious that one could be use in that case.
* Second where the unit of work have an instance to the repository which have an instance to the service layer..
[URL]
What would be better ?
View 11 Replies
Apr 1, 2010
what is the difference between these two patterns?
View 1 Replies
Jun 1, 2010
the more i read about pattern the more i get confused!
In particular i'm trying to get the relationship between Registry and Repository.
Is it correct to say that a possible implementation of a Registry uses a Factory to return an appropriate Repository which, in turns, uses an underline DataMapper to performe the CRUD operations against a database?
If no, which kind of relationship exists between repository and registry ?
View 1 Replies
Feb 4, 2011
I am trying to understand the fundamental differences between the Provider Model and Repository Pattern.
I have used the Provider Model in many many situations and am confident with it when designing applications. However, the more examples I encounter on the internet and asp.net evolution I keep coming across "Repository" Interfaces for classes that look like a Provider Model.
I have dug around a bit but all I can see is that they kinda do the same thing, or closely overlap by enforcing an inheriting class to adhere to a "contract" of implemented / abstracted methods etc...is there more to it?
View 1 Replies
Jun 1, 2010
I was trying to find out how to search a repository and ensuring the results returned are only for the items in the repository which match the search text. For example:
[Code]....
Where i have "where s.SupportIssueID.... I want only the results which have an ID that matches or is LIKE the given "searchText". I thought I could use s.SupportIssueID.Contains but this isnt available in the helpers.
View 2 Replies
Mar 4, 2010
I'm used to working directly with SQL and do NOT want to use Linq.
Pretty much I always create a class like the one below and have all the functions/methods necessary to perform a task.
How would I set up a repository without using LINQ??
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
[Code]....
View 5 Replies
May 12, 2010
I have built my first MVC solution and used the repository pattern for retrieving/inserting/updating my database.
I am now in the process of refactoring and I've noticed that a lot of (in fact all) the methods within my repository are hitting the database everytime. This seems overkill and what I'd ideally like is to do is 'cache' the main data object e.g. 'GetAllAdverts' from the database and to then query against this cached object for things like 'FindAdvert(id), AddAdvert(), DeleteAdvert() etc..'
I'd also need to consider updating/deleting/adding records to this cache object and the database.
What is the best apporoach for something like this?
My knowledge of this type of things is minimal and really looking for advice/guidance/tutorial to point me in the right direction.
View 2 Replies
Nov 2, 2010
I'm working on adding an HtmlHelper for pagination, but I am unsure where the proper and/or most beneficial place to put certain parts of the pagination code from a performance and maintainability standpoint.
I am unsure if the Skip(), Take() and Count() portions of Linq to SQL data manipulation should live within the repository or the controller.
I am also unsure if their order and where they are used affects performance in any way.
If they live within the repository from my understanding this is how it would work:
1. I would pass the pageIndex and pageSize as arguments to the repository's method that grabs the data from the database.
2. Then grab the full data set from the database.
3. Then store the count of TotalItems of that full data set in a variable.
4. Then apply the Skip() and Take() so the data set retains only the page I need.
5. Display the partial data set as a single page in the view.
If they live in the controller from my understanding this is how it would work:
1. I would grab the full data set from the repository and store it into a variable inside of the controller.
2. Then get the count of TotalItems for the full data set.
3. Then apply the Skip() and Take() so the data set retains only the page I need.
4. Display the partial data set as a single page in the view.
Inside the controller (I realize I will incorrectly get the page count here and not TotalItems):
[code]....
View 2 Replies
May 18, 2010
I am new to MVC and this really probably should not be posted here but in a different forum topic. The reason I am posting here though is I am not sure if there is something about MVC that would prevent me from doing what I am looking to do.So here it goes.Maybe I am the only one out there that thinks this way but I don't care for and don't fully understand LINQ. I Like building my stored procedures passing my data to a datareader etc... and displaying what I need.
Now that being said I am wanting to learn how to make a true Data Repository and build from there but everything I find online especially here all gives me examples and instructions on how to do so using LINQ.Does anyone know of a site that will teach me how to do this without using LINQ or any form of ORM just allow me to write my stored procs how they need to be and build my classes for data access how they need to be.I may be wrong in this but it seems to me this would be the more light weight way of doing it.Anyhow as stated above the additional question to this would be is there any reason this would not work for MVC and actually any reason it is extremely (or at least for me) hard to find any documentation on this anywhere online?
View 3 Replies
Oct 11, 2010
I need to create a search engine for my website that searches my entire content and files stored in a database.What is the best way and easy to accomplish this?If can, please provide a few samples or links.
View 4 Replies
Jul 22, 2010
not sure if I'm posting to the right thread or not.. but here is the questiondoes anyone know how to implement a best pratice on SEO?One of the example is: if the user types "brand new canon camera" then I want the system to find a sequence of string in the database that contains "new", "cannon", "camera". It is ok with or without the word "brand". However if the user types "HP laptop DV1000" and i want the system to find all HP laptop whether new or not but limited to specific series.
View 3 Replies
Nov 21, 2010
I am wondering if there are any good articles you could point me to that would present the implementation details or options for delivering advanced search capabilities. Like what we see at [url] and similar Web sites offering vast numbers of products to be searched. The search process for these starts with a simple "Search" text box - usually with auto-suggest. Then the user can drill down and narrow the search by [for example] price, manufacture, size, capacity, and other relevant attributes of the product being searched.
When I navigate such sites and search for products, drilling down into the various categories, it's easy to think that there is some complex engine behind the scenes that generates dynamic SQL to satisfy the various and potentially extensive criterion required to satisfy the search requests.
Or could it be simpler than that? In any case, I understand this question may not have a specific answer; so I'm hoping for some article or reference implementation I could study. Short of that, if any of you have implemented advanced search of a product catalog (presumably searching products stored in a reasonably normalized database; through 3NF or so); any critical implementation considerations would be appreciated. I'm particularly interested in the meta data that may have to be present in the underlying data set in order to satisfy some of the search requests.
View 2 Replies
Sep 14, 2010
how will I able to create an Image Search Engine?
It is about using an Image and search similar images on web.
View 1 Replies
Nov 22, 2010
Does anyone has a idea how to write code for a search box to look for keywords,etc inside the website or sitemap?
View 11 Replies
May 3, 2010
I would like a site that offers the users the possibility to search over 2 datasources but as i tried to indicate in the subject title the searches are one after another where the result of search 1 is used as a parameter for searching the second datasource. The order of the search would depend for what you search (ideally). Some "fields" or "data" of course appear in both datasources.
To get more specific: datasource 1 contains chemical structures and the associated "id" for this structure + additonal properties. You can search for chemical structures here. (chemically intelligent system). datasource 2 contains documents which are indexed (full text) and have metadata fields one of them beeing above id. No chemical search possible.
The idea is now that i perform a search by chemical structure on datasource 1. As as a result I get a list of id's. These id's are then past into datasource 2 as parameter + also all additionaly parameters entered. There are API's available to perform above searches on the 2 datasources. Is this a reasonable approach? Would it be better to create somekind of a simple datawarehouse, eg a table with all numbers linked to all documents they appear in? (would't know how to achievie this actually since it's the 2 datasoruces are not the same rdbms).
View 2 Replies
Nov 18, 2010
I want to use Linq to SQL in my web projects. I mostly work in small and medium size projects. Please guide me what layers I should use ?
Previously I was using DAAB and was using 4 layers (business objects, business logic layer, data access layer and user interface).
View 5 Replies
Mar 10, 2010
I've created a photo database and search engine that creates a xml that corresponds to the multiscale image xml.My problem is how to enable multi users to search at the same time?
View 1 Replies
Mar 18, 2011
I have a query which need to search on account table where search criteria looks at either partial name(string column) or partial accountid (integer column).
Linq doesn't allow tostring on integer column to find partial search. The example would be search account number which begins with 124. There might be account numbers like: 1247, 1249 etc which need to be returned. On the name side, searching for string that begins with joh would return john, johk, johp etc.
FYI: The query should return Account table records not annonymous types.
[Code]....
View 17 Replies
Jul 27, 2010
We have a web solution. In it we have 2 websites and a core project in the core project are some classes that encapsulate data that a database utility class searches using sql and populates the entities. The entities are stored in generic lists.
We have just upgraded our project and I want to start using linq, I was wondering the best way to go about it. SHould I creata new linq project? Or Should I just use ling on new pages only and stick to our current data access layer for pags that already exist?
Its vital that we start using linq as it will save us time in the future
View 2 Replies
Mar 13, 2011
i build online course selection for a university now i want to make it layering and i dont know to make it 2 layer or 3 layer i mean mix business layer and database layer because i use linq so it is not require to check request data that in sql from client in business layer because linq check it autimatically to preent injection and etc.is it right?can i put my class and DB class in same place or layer?if i make it 2 layer the performance becom better?
View 5 Replies