I have three layers like UI, business and data access in my asp.net web application project. If I pass say a company code from the UI to the business to the data access and I query the company details like company name, address, phone etc from the database using sqlhelper executedataset() which wil return me a dataset. Then how do I pass these company details back to the UI layer. Is it correct to just pass the datatable object to the business and UI.
I'm trying to create my first Asp.Net application from scratch. Tried to create this post in some of the other forums but I couldn't find a better place.
So, as the title says, I'm having trouble trying to model my application. I'm like an OOP newbie. I'll show my classes first and then I'll write my questions.
Model Layer
public class User { private int id; public int Id { get { return id; } set { id = value; } } private string login; public string Login { get { return login; } set { login = value; } } private string password; public string Password { get { return password; } set { password = value; } } } Data Access Layer public class BasicDAL { private SqlConnection connection; //>>Returns a new connection to the database public SqlConnection GetConnection() { //>>If connection is active close it before starting a new one if (connection != null) if (connecion.State != ConnectionState.Closed) connection.Close(); connection = new SqlConnection("MyConnectionStringHere"); return connection; } } public class UserDAL : BasicDAL { //>>Insert a new user public void Insert(User user); { /* Insert into DB */ } //>>Authenticate user login with its password public void Authenticate(User user); { /* Authentication code here */ } } Business Logic Layer
[Code]....
So, model layer is pretty simple. Just a user representation. On the Data Access Layer I have a basic class with a GetConnection method. All DAL classes will extend this one.
My first problem lies on Business Logic Layer. With the above scenario, I've placed the same methods that I placed at the DAL. BLL methods would call DAL. As simple as that but I believe It is not the best way to do it, is it? How can I improve those classes?
Also, I have to "try..catch" blocks. That's because I can't find good places for it. I mean, if I place a try..catch on GetConnection method, for instance, how my ASPX page would get this error? How my ASPX page can tell the difference between "database offline" and "sql syntax error" when executing "userBll.Insert(newUser);".
My problem is mainly placing the exception handlers. I understand I would probably have to change return type of some methods. I didn't change because I believe that will have something with the exception handlers.
Btw, please assume I can't use TableAdapters and stuff like that. I would like to create all layers by myself.
In my application, I'm binding a Collection of Supervisor type, which I'm feeling that it is an additional overhead. Becuase I only want his ID. So binding an object collection to the dropdown which seems no worth.
I am thinking to use entity model as DAL, how should I create the BLL then? What kind of datasourceobject should I use in the asp pages?
I am looking for best practice to use Entity framework 2 in the three layers design. I had experience at dataset with three layers design.
Should I use objectdatasource at the pages for gridviews? My guess is that entitydatasource by passed the BLL which is not good, so the only option left is the objectdatasource.
Could and should my BL object inherit those entity model in the DAL, so I dont need to recreate their object's property?
I have a quick question in regards to testing my validation. I have been looking through a few MVC examples and have noticed the 'Validating with a Service Layer' tutorial which is pretty nice. It discusses how to abstract your code out etc..My question is, that they have validation occuring in the service layer, if errors occur, the error + message then gets added to a model state dictionary.Now i want to test my model to make sure my business rules are being applied to it, but with this approach, for starters, the Validation method is not in the interface. Now, if the validation method was in the interface, during testing you would have to re-implement the validation on the testing side.Am i missing somthing? Where should your validation code go? I feel like it should go in the model, but then i have to track the errors on the model side.
I doubt how to implement the layers FACADE, BLL and DAL, using DTOs specialized .. where:
public class ClassA { private int _Test1; public int Test1 { get { return _Test1; } set { _Test1 = value; } } } public class ClassAB : ClassA { private int _Test2; public int Test2 { get { return _Test2; } set { _Test2 = value; } } } public class ClassAC : ClassA { private int _Test3; public int Test3 { get { return _Test3; } set { _Test3 = value; } } }
In the database, there is the 3 tables, as described above.how do I implement the facade, bll and dal? only one class for 3 DTOs?
It's appreciated if you could share your thought.I have seen a e-commerce website design which have a few layers:Common,DataAccess,BusinessLogic,Operational.In the Common layer,it includes all the classes with only attributes and properties,no methods nor data access codes here.
In the DataAccess layer,there is a class for each action per class in the Common layer.For example,
a class for the Select action of class A of Common layer, a class for the update action of class A of common layer, a class for the Select action of class�B of Common layer, etc... Is this a design I could use for a potential high trafic website?What's the pro and con of this design.
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
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?
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?
I am updating a project I wrote some time ago. At the time my preference was for DataSets and DataSetTableAdapters, but I've now moved on to use Linq to SQL DataClasses. I would like to convert the project to Linq to SQL, but I am tight on time and it's a big job. My question is, is there any reasons I can't develop new modules using Linq to SQL DataClasses along side DataSets and convert the DataSets overtime?
Apart from the obvious confusion it will cause, are there any technical problems I should be aware of i.e. will there be any performance problems using the two methods?
I'm currently trying to work out the best way to build this web application, which will then be intergrated on other systems, such as WinForms, Intranets etc.
We hope to include the usual layers i.e. DAL, BLL, BOL and UI but I have been experimenting with Entity Framework 4 and WCF Data Services and managed to get something in place where I was using WCF as a gateway to EF4.
i.e. Adding a Service Reference to my project and then using the EF4 context and writing LINQ queries against the DB
e.g.[Code]....
Now with the current setup I would still need to write a DAL Class Library, that interacts with the Data Service, because as I said WCF Data Services only seems to be a gateway, I can't see where to put the code (above) in the Data Service and then how I could these methods.
My questions are: 1. How do I develop a WCF Data Service in such a way to allow this behaviour - I know how I could do it using ASMX web service, something like [Code]....
2. If I am to use WCF Data Services, how is serialization handled (if at all) - again I know how to do something in ASMX web services
3. Again, If I am to use WCF, how do I add Security and only allow my applications to access the web service - for obvious reasons
4. Would it be possible / logical to also include the Business Logic Layer into the web service?
how the WCF, DAO and DTO layers communicate with each other? I would appreciate if someone can specify which layer comes first and then how it interacts with the next layer
I have a form with mulptile panels hidden behind others. It is impossible to edit them in design mode without moving them to the side so that all panels are visible, so that is what I do. I use JavaScript to position the panels during runtime, but it is an innefecient way to do it.
Is there a way to make a panel or layer visible or invisible while working in design mode, kind of like autocad works
While designing (and then implementing) a layered application:
Is it correct to use the same ORM objects accross all layers? (which would go against encapsulation).
Or the presentation, business and data layer should each have their own objects? (which would lead to lots of code repetition).
e.g. (just to illustrate the question): if one uses Linq to SQL in the Data Layer and Visual Studio's O/R designer to generate the ORM objects, are those objects supposed to be used in the Business and Presentation Layers as well.
i.e.: Are the objects associated with the entities that the application handles a crosscutting issue?
Split off from http://forums.asp.net/t/1618613.aspx
I would like to get your advise on Dependency Inversion..Should i include it as a layer between Business Layer and Repository Layer?
I think its really great when different team members work on DAL n BAL etc or when your database will be changed in future. It actually removes the dependency of the Data provider but over the expense of additional coding overhead. My question is , is it really worth it? If i suggest this layer to my PM and give him the above two reasons then i dnt think he will accept it since most of the time each developer works on his DAL/BAL's, and Change in DB wud be the least of his concerns.
RAD in every layer..
I mean if there are any auto generation tools available for generating repositories etc.I read about MVCContrib Grid and i think its a good option to use for Grid.
If i use Spark ViewEngine then can i still use T4 templates to auto create custom views by customizing templates?
I am trying to work out the best way of dealing with a mailinglist class I have written. I got a simple form on the page where people can add their email address. Depending on which page they add their email address they join a differnet mailinglist. So from the form I have 2 values passed to the DAL {mailinglistID} and {email} - Various checks are done in the DAL, such as checking if email exists, checking if email exists in that mailing list etc etc.
I would like to be able to present the status codes on the page, so in the DAL I return a number value and from the BLL return a string depending on the number value. DAL returns 1, means email exists in mailing list, BLL see's the 1 and returns "email exists" to the page.
I have no idea if this is the right way of doing it or not - the (problem or question) is that in the content page I am checking the if the returned string is "" or has a value, and presenting the message in a visable div.
Is this the best way to do this, or should the status value be converted to a message on the code behind of the content page.
(of course I could have got this all wrong, and need to start again.
i am creating a class library project and adding new ado.net data model into it. created model automatically generetes codes. ModelENtities and entity classes.
i want to separate ModelEntities context class and entity calsses to two layer as two class library. is this possible?
assume that I do this and when I update the model from database , do separated classes update?
I have a theoretical question.i have a function in DAL that does a select sql query. and these are my questions:
I was told that it's not appropriate to pass datasets between layers. so how should i pass the results? which value should i return to the BLLBAL (i thought of a List<>).? and to the presentation layer.
currently my implemention is like that:
SqlCommand cmd = new SqlCommand("getRequestById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@requestId", rId)); SqlDataAdapter datAdp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); datAdp.Fill(ds,"getRequestById"); List<String> rs = new List<string>(); for (int i=0; i<11; i++) { rs.Add((Convert.ToString(ds.Tables[0].Rows[0].ItemArray.GetValue(i)))); } return (rs);
is it better to create xsd file in VS2010 with only fill (all other implemtation i'll do on my own) property.
I added New Item, DataSet, over that i added tableadapter with stored procedure. i declared that it will do only the fill property(without returning the data). i want to implement all the other properties by demand in my way.
i wrote in the dal test.getRequestById1DataTable dt1 = new test.getRequestById1DataTable() how can i get the data and pass it between the layers?
If I have a 3 layer web forms application that takes user input, I know I can validate that input using validation controls in the presentation layer. Should I also validate in the business and data layers as well to protect against SQL injection and also issues? What validations should go in each layer?
Another example would be passing a ID to return a record. Should the data layer ensure that the id is valid or should that happen in BLL / UI?
I have a query about asynchronous paging using RegisterAsynchTask or AddOnPreRenderCompleteAsync
If I have a 3 tier web application with the UI, Business Layer and the Data Access Layer and I'm doing the Begin and End asynchronous processing of a method at page level (UI). This UI method accesses the DB and goes through all the layers starting asynchronously from the first page, then continuing "normally" through all the other layers. These underlying layers are all synchronous but started asynchronously through the first Page.
My question is how should asynchronous paging processing be handled with regards to layers? Do I need to set the methods being used at all levels asynchronously (using Begin and End event handlers) ?
And what about MasterPages... I can't Asynchronous processing for them. RegisterAsynchTask is not available and neither AddOnPreRenderCompleteAsync.... what I'm missing?