Is CSLA.NET useful for my project?

Is CSLA.NET useful for my project?

Old forum URL: forums.lhotka.net/forums/t/6792.aspx


StoreIntegrator posted on Tuesday, April 14, 2009

Hi,

I read some discussion on the forum and tried to download some code samples. I have been using my own DAL in the past for my DNN (Dotnetnuke) applications since DNN DAL is missing the nullable integer, datetime etc. Also I do not like retyping a tedious DAL. Now I am charmed by LINQ and I used the PLINQ of CodeSmith. I think it is not really a Business Layer, but more a Data access layer.

I miss for a web application some things:

  1. Caching the datalayer (DAL); DNN does not support SQL cache dependency nor ASP.NET output caching. I also would like to cache certain data objects. Also some there are some nice LINQ extensions out in which you can easily case data like .Where(i =>i.ItemId = itemId).Cache(10) where 10 is the number of minutes in the cache.
  2. The PLINQ uses compiled queries which are nearly as fast as Stored Procedures. But then easier to maintain.
  3. I like the LINQ since you do not have to write Stored Procedures and a datamodel change is reflected fast in your code due to the strong typed DAL.
  4. I would like to call static objects so that I do not have to bother with datacontext etc. Just CustomerManager.Load(customerId) or ProductManager.Load(productId), and ProductManager.Save(product). In these functions the create datacontext, sql etc. is present then. Similar for an product. If you would like to have the ProductTranslations a simple Product.Translation would get the data. Now it seems I need to code the Business Layer on top of the DAL created with PLINQ of Codesmith.
  5. I miss some bulk data operations like multiple row updates or inserts in the LINQ itself. I used a data adapter in the past for it, but with LINQ it seems you need to iterate every single record to the database.

I think 1. and 4 are most important for me. Is CSLA.NET then something for my store project?

Any help appreciated. In particular is there is some sample project with code smith template that shows the implementation of 1 and 4.

J.

RockfordLhotka replied on Monday, April 20, 2009

1) If you are using the data portal, you can do caching (using static fields or System.Web.Caching) in your object's factory methods. That is a powerful technique that works even if the UI technology (DNN) doesn't support caching.

4) This is exactly how CSLA is designed to work. The preferred model for building a CSLA object is to implement static factory methods that use the data portal to create and populate the object instance.

If you are totally fixated on PLINQ though, and it sounds like you are, then I don't know if CSLA will be a great fit for you. PLINQ (or LINQ to Objects in general) is about reshaping sets of data objects into other data objects. And that's a fine thing.

But it isn't what CSLA is about. CSLA is about creating objects based on behavior, not data. While reshaping them is fine to an extent, the reality is that if you are reshaping a CSLA object model (beyond sorting and filtering of collections), then you just have a broken object model and you should really rethink your object design...

It sounds to me like you need to step back and decide whether you want data-centric objects or behavior-centric objects. If you want data-centric, CSLA isn't a great fit. If you want behavior-centric, then CSLA should be a great fit.

StoreIntegrator replied on Sunday, May 03, 2009

Dear Rocky,

Seems that point 4) is in CSLA. Where can I catch up information on how to generate a CSLA for my MSSQL database objects? I would like to see some samples of how the generated logic looks like. I am also interesting to know if somebody can generate a DAL for me or show me some additional guidance in using the CSLA codesmith templates.

You mention filtering. In LINQ this can easily be done by passing an additional WHERE clause to the database server so that the data returned is limited ('filtered') by this WHERE clause. I think the CSLA objects are filtered on the web server ? That makes is heavier than using LINQ?

Any help is appreciated.

Best Regards,

J.

JoeFallon1 replied on Sunday, May 03, 2009

You have a lot of wrong impressions about CSLA.
The first thing you should do is buy and read the book.

CSLA will retrieve data from the database using any data access technology you wish. I happen to use ADO.Net and datareaders since they are the fastest. So CSLA is "lighter" than LINQ if you use ADO.Net. The advantage to using LINQ to SQL is its ease of coding and implementation.

If I pass a WHERE clause in my SQL statement then the filtering occurs in the database.

Sometimes a list can be retrieved and you may only want to view a subset of it at any given time. Yet you still want the entire list available in memory. This is the case where you could filter it on the client (or web server).

I do not think that anyone is going to generate a DAL for you. (But I could be wrong.)

Joe

RockfordLhotka replied on Sunday, May 03, 2009

Joe’s reply is very good. Don’t confuse CSLA with an ORM – it is not an ORM. CSLA helps you build a distributed business layer, not a data access layer.

 

Also, you say that filtering can be done in LINQ by passing a where clause to the database. Don’t confuse LINQ with LINQ to SQL. LINQ to SQL is one tiny part of LINQ, and is actually something that Microsoft has indicated is not on the strategic path.

 

Yes, L2S allows you to filter data in a query, but any data access technology allows you to do that. CSLA is not a data access layer, but it does provide a rich business layer (or more accurately helps you create one). You could do filtering in the business layer, or even the UI layer (some data grid controls do it). And sometimes that makes sense, especially for smart client apps (Silverlight, WPF, etc). CSLA also allows you to push the filtering concept into the data access layer, and sometimes that makes sense, especially for web apps, or any app where there are thousands of rows of data.

 

The point is that there’s flexibility so you can choose the right answer for your particular situation and application.

 

Rocky

 

StoreIntegrator replied on Monday, May 04, 2009

Hi,

Thanks for the quick replies. I have ordered the book at bol.com since CSLA seems interesting. I have seen you use the Catalook Dotnetnuke store for paperbacks. I want to use CSLA for my DNN shopping engine I am creating. I have my own CodeSmith that generates stored procedures and DAL (so is it called in DNN). I have not yet a code template for Caching and static calls. For that reason I am looking what can be interested. In particular since I am also using webservices and in the future Silverlight. It would be easier to judge if some code samples would be present for a database.

Any help appreciated.

J.

RockfordLhotka replied on Monday, May 04, 2009

The ProjectTracker application is the primary reference application for CSLA .NET, and it uses a database (via LINQ to SQL at the moment) for a data access layer.

 

Rocky

RockfordLhotka replied on Monday, May 04, 2009

StoreIntegrator:

I have seen you use the Catalook Dotnetnuke store for paperbacks. I want to use CSLA for my DNN shopping engine I am creating.

In my view, there's certainly a market opportunity for you - the Catalook store is overly complex, really hard to configure, harder to style and doesn't have good support for selling downloadable content.

On the other hand, it is really cheap. Unfortunately in this case I think I got what I paid for :(

StoreIntegrator replied on Wednesday, May 06, 2009

Hi Rocky,

Currently no software download is in my roadmap. At the time I have resources for that I will contact you. It is interesting that you talk about LinQ to SQL project "The ProjectTracker application is the primary reference application for CSLA .NET, and it uses a database (via LINQ to SQL at the moment) for a data access layer." Can I download that to see how that uses a static DAL, or it that also not having it?

J.

RockfordLhotka replied on Wednesday, May 06, 2009

I don’t know what you mean by “static DAL”.

 

ProjectTracker uses the DataPortal_XYZ model and in the DataPortal_XYZ methods it uses L2S to interact with the database. So yes, if you download ProjectTracker and look at the code you’ll see how to use L2S to create a DAL behind CSLA objects.

 

Also Chapter 18 of the 2008 book discusses this, and other data access options supported by CSLA .NET.

 

Rocky

 

StoreIntegrator replied on Sunday, May 10, 2009

Hi,

I have not received your book yet. I think this week it will arrive.

With static I mean:

In DNN you use to write:

AddressController addressController = new AddressController()
Address address = addressController.GetAddressById(1)

Static is:

Address address = AddressController.GetAddressById(1)

Same for a CRUD:

AddressController.GetAddressById(1)
AddressController.Update(address)
AddressController.Delete(1)
AddressController.Create(address)
AddressController.List()

J.

RockfordLhotka replied on Monday, May 11, 2009

CSLA requires the use of factory methods. Well, that’s not entirely true, but it encourages the use of factory methods.

 

You can create your factory methods as static methods – which is what I usually do.

 

var customer = Customer.GetCustomer(123);

 

Or you can create factory classes, with factory methods

 

var factory = new CustomerFactory();

var customer = factory.GetCustomer(123);

 

Either approach is fine. The first one is simple and easy to implement. The second enables the use of dependency injection and other “fancy” patterns – but honestly there’s little value to taking that approach since the typical factory method just invokes the data portal, so there’s already a great deal of abstraction involved, and adding more abstraction offers little value.

 

Rocky

 

 

From: StoreIntegrator [mailto:cslanet@lhotka.net]
Sent: Sunday, May 10, 2009 4:34 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: Is CSLA.NET useful for my project?

 

Hi,

I have not received your book yet. I think this week it will arrive.

With static I mean:

In DNN you use to write:

AddressController addressController = new AddressController()
Address address = addressController.GetAddressById(1)

Static is:

Address address = AddressController.GetAddressById(1)

Same for a CRUD:

AddressController.GetAddressById(1)
AddressController.Update(address)
AddressController.Delete(1)
AddressController.Create(address)
AddressController.List()

J.



StoreIntegrator replied on Sunday, May 24, 2009

Hi Rocky,

I have received your book. Quite impressive, but honestly: 768 pages....say 5 min per page...oeps...my wife will be angry with me...not talking about the kids.

I have studied a bit the dataportal. I see your point about the factory, but how to generate such dataportal for say 30 tables on the fly including the stored procs ? Maybe in your next edition you can devote a chapter to it? I am more practical: this sounds good, I want to use it for my business logic. So if I use the CodeSmith templates I generate a Business logic from my database on the fly including stored procedures and webservices?

I also read a bit about subsonic and Entity Framework....I feel Entity framework is not that far yet, but might be appealing also? I am convinced that Linq to Sql will not be suited for this. What do you recommend?

J.

rfcdejong replied on Tuesday, August 25, 2009

An old post, but i do like it. I'm wondering if StoreIntegrator got any futher with the DNN module using CSLA.

StoreIntegrator, are u still reading the forum?

Copyright (c) Marimer LLC