Oxite, An open source CMS based on ASP.NET MVC by Microsoft

By Mohammad Mahdi Ramezanpour at December 09, 2008 20:30
Filed Under: Microsoft, ASP.NET, ASP.NET MVC, LINQ, SQL Server

 Oxite Logo - Photo taken from http://www.codeplex.com/oxite I know it’s a little old but in this post I want to talk about Oxite.

Oxite is a new open source blogging system based on ASP.NET MVC which built by Erik Porter, Nathan Heskew, Mike Sampson and Duncan Mackenzie.

This is a simple blog engine written using ASP.NET MVC, and is designed with two main goals:

· To provide a sample of 'core blog functionality' in a reusable fashion. Blogs are simple and well understood by many developers, but the set of basic functions that a blog needs to implement (trackbacks, RSS, comments, etc.) are fairly complex. Hopefully this code helps.

· To provide a real-world sample written using ASP.NET MVC.

As they said, this blog engine built not only for developers and as sample and this has been used in MIX Online too.

Here is some other information from http://visitmix.com/lab/oxite:

Oxite was developed carefully and painstakingly to be a great blogging platform, or a starting point for your own web site project with CMS needs. Its line-up of sexy attributes includes: provider-based architecture allowing you to swap out database and search providers (SQL Server DB, local and Live search providers included), built for testability and hence most likely to be voted "hottest in class" by TDD fans (repositories, everything has an interface, etc.), database file and string resource storage so that files get stored in database and strings stored for localization, built to take full advantage of ASP.NET MVC but broken into assemblies so that even ASP.NET WebForm developers can use the data backend and utility code, supports use of Visual Studio Team Suite (DB Pro, Test, etc.), and Background Services Architecture (sending trackbacks, emails, etc. all done as a background process to prevent delays on the web site itself).

Download it now and get some other information by click here

Visual Basic 2010 new features

By Mohammad Mahdi Ramezanpour at November 19, 2008 21:39
Filed Under: .NET General, LINQ, XML

Channel 9 Logo - Photo taken from: http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.pngWorking with new technology is always interesting. Since Visual Studio 2010 and .NET Framework 4 have been announced, most of developers who are developing with Visual Basic start searching about Visual Basic 10 new features.

About a month ago, Lucian Wischik and Lisa Feigenbaum described about new features in Visual Basic 2010. The show is available for download at MSDN Channel 9 website.

You can check it out by click here.

This is my recommendation: View it!

How to implement SQL LIKE keyword in LINQ to SQL

By Mohammad Mahdi Ramezanpour at November 17, 2008 18:27
Filed Under: .NET General, LINQ, SQL Server

It’s about a year that .NET framework 3.5 has been released. Most of companies are still using SqlConnection, SqlCommand, SqlDataAdaptor, etc. in order to manager their data connections. About 5 month ago I started posting articles about LINQ to SQL and ways you can use in order to use LINQ as a very powerful data source.

In this post I’m going to show how you can implement SQL “LIKE” keyword in LINQ to SQL.

As you may know, SQL Server has 3 kind of LIKE keywords (%LIKE, %LIKE% and LIKE%). For each of these types, you have to use of specific LINQ to SQL:

LIKE%:

LIKE% selects all rows that start with an expression, for example:

SELECT Title, LoginID FROM HumanResources.Employee 
WHERE Title LIKE N'Acc%'

Here is the return value:

SQL result after using LIKE keyword

In order to implement such a thing in LINQ to SQL you have to use the StartsWith() method like following:

private void ImplementStartsWith()
        {
            AWDataContext db = new AWDataContext();
            var i = from item in db.Employees
                    where item.Title.StartsWith("Acc")
                    select new {Title = item.Title, UserName = item.LoginID };
            dataGridView1.DataSource = i;
        }

%LIKE:

%LIKE selects all rows that end with an expression. For example, I want to have all managers so I select titles that end with “Manager”. EndsWith() method will help you out for this:

private void ImplementEndsWith()
        {
            AWDataContext db = new AWDataContext();
            var i = from item in db.Employees
                    where item.Title.EndsWith("Manager")
                    select new { Title = item.Title, UserName = item.LoginID };
            dataGridView1.DataSource = i;
        }

%LIKE%:

This like is the most useful like type that is using for searches. If you want to have all rows that contain an expression, you must use Contains() method:

private void ImplementContains()
{
        AWDataContext db = new AWDataContext();
        var i = from item in db.Employees
                where item.Title.EndsWith("Specialist")
                select new { Title = item.Title, UserName = item.LoginID };
        dataGridView1.DataSource = i;
}

The power of Visual Basic 2008 in XLINQ

By Mohammad Mahdi Ramezanpour at October 16, 2008 10:31
Filed Under: LINQ, .NET General

Using LINQ to XML (XLINQ) will help you to access your XML data very easier, like never before. But I don't know why, using XLINQ in Visual Basic is more interesting than C# for me.

In this post I want to show you how easy can be for VB to generate an XML file than C#.

Assume that we want to generate an XML file like following:

<?xml version="1.0" encoding="utf-8" ?>
<configs>
    <config name="Mohammad Mahdi Ramezanpour"></config>
</configs>

In order to generate such a thing in C#, you will need to write something like this:

XDocument xdoc = new XDocument();
XElement xroot = new XElement("configs");
XElement xitem = new XElement("config", 
                 new XAttribute("Name", "Mohammad Mahdi Ramezanpour"));
xroot.Add(xitem);
xdoc.Add(xroot);
xdoc.Save("C:\\sample.xml");

As you can see, I just created a new XDocument and then add some XElements to it. All things are very routine and then I saved the data into an XML file "C:\sample.xml".

Now, lets check such the code above in Visual Basic:

Dim xdoc As New XDocument
Dim xroot As XElement = <configs></configs>
Dim xitem As XElement = <config name="Mohammad Mahdi Ramezanpour"></config>
xroot.Add(xitem)
xdoc.Add(xroot)
xdoc.Save("C:\sample.xml")

in the code above I created an XML file exactly like our previous example and the result will be equal.

Lets take a look at this code snippet; In Visual Basic when you declare a variable as XElement, you can write your XML content exactly like the syntax you're using in an XML file. It means that you can use XML tags (<configs></configs>) straight in your code.

As I said in my previous posts, I like VB more than C# and I thing VB is much powerful than C# at least in this part :).

How to use LINQ to SQL for binding data in CrystalReports 2008

By Mohammad Mahdi Ramezanpour at September 10, 2008 01:54
Filed Under: .NET General, ASP.NET, LINQ

Today I just decided to create some reports for one of our customers in Visual Studio 2008 and .NET Framework 3.5. Because I'm developing this application using LINQ, I wanted to use LINQ to SQL in CrystalReports. In this post I want to show you how you can use LINQ in order to bind data in CrystalReports.

Add CrystalReportViewer

At first, all sections are regular. You need to create a new application (I used Windows Application) and then add a Crystal Report Viewer to you specified form. When you add this control, you will see that Visual Studio added five new references to your application. These references are:

  • CrystalDecisions.CrystalReports.Engine
  • CrystalDecisions.Enterprise.Framework
  • CrystalDecisions.Enterprise.InfoStore
  • CrystalDecisions.ReportSource

You will need these libraries in order to let your application work with CrystalReports.

You made a place to show your reports in. Now you have to get started and create some reports. I want to add a new report by right clicking on my project, point to Add and then New Item. In the list of new items you need to point to Reporting section on the left side of "Add New Item" form and select Reporting. You items on templates side will be filtering to just 3 items:

  • Crystal Report
  • Report
  • Report Wizard

We want to work with CrystalReport here but for now I want to tell you other 2 items will work with Microsoft SQL Server Reporting Service that enables you to create flexible reports like CrystalReports but because CrystalReports is more common, most of developers prefer to use CrystalReports.

We just select Crystal Report and then select Add.

Because we want to work with LINQ classes, I need to create a LINQ to SQL class in order to add my tables to it and then use it in my CrystalReport file (For information about how you can create a LINQ to SQL class, Just check out my previous post: How to use SQL "IN" keyword in LINQ). Here is my tables structure:

LINQtoSQLClass

All I want is to show records from my Articles table. So I should implement this in my report. As you know when you're working with LINQ to SQL, tables become classes and fields become properties of those classes. When you want to add a new data source to your CrystalReport file (Data Fields section), there are some possibilities. You can use ADO.NET Datasets that enables you to use datasets you implemented in your application; and also you can use .NET Objects. It means that you can use classes in your application to be a data source for your report file. Because LINQ is based on classes, You must use .NET Objects in order to use LINQ to SQL as your Report's data source.

When you expand .NET Objects, you can see all classes in your application and also you can see the classes that made by LINQ class designer. Because I want to use my articles table I have to select Article class in the list as shown below:

Selecting Article Class

If you select this class as your data source you can see all fields available in the Articles table in database field section of our crystal report file. It means you can add each field you want to your report. So I just want to add Title field to my report (Details section):

Add Title To My Report

OK. That's all we need in our report file. Just one section left and that's let your report file know what data to show. You need to assign a database query to your file.

Let's go back to our report viewer file and go to code-behind section. In order to set your report file's properties, you have to create a new instance of your report file as following:

CrystalReport1 rpt = new CrystalReport1();

Now it's time to specify a query to your report file. A CrystalReport report file has a method named SetDataSource() that takes a datasource as the following types:

  • DataSet
  • DataTable
  • IDataReader
  • IEnumerable

LINQ to SQL, enables you to convert your data to a List<entityType>, Array and more. As you know List inherits IEnumerable, so All you need is to create a LINQ object and add a ToList() method to it and finally set the "SetDataSource()" method to our LINQ object as you can see in the code below:

ReportSampleDBDataContext db = 
    new ReportSampleDBDataContext();
var data = (from records in db.Articles 
            select records).ToList();
rpt.SetDataSource(data);


There is a property in our CrystalReportViewer control name ReportSource that enable you to specify which report file you want show in your CrystalReportViewer control. So you must set it up:

crystalReportViewer1.ReportSource = rpt;


It's working fine, isn't?

Currently Reading

Quote of the day

Send Persian SMS