Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, December 10, 2010

Why I hate VB now even it was my native language once…


ShareThis

I started coding in VB4 language and did a lot of coding on VB 6 for many years. Those days, VB was my native language. I was fond of it. I loved it. I used to think in VB Smile

But when I learnt JAVA and then C#, I never VB again. C# is really amazing.

There are a couple of reasons I do not use VB -

  1. VB is verbose
  2. The intellisense refuses to "let go" unless I tap the Escape key
  3. Syntax highlighting sucks. In C#, all types are highlighted - in VB, only intrinsic types are highlighted.
  4. It's VB. Winking smile
  5. There are no automatic code formatting options like we get with C#

But still I know there are a couple of things that can be better done in VB.net.

Wednesday, August 4, 2010

Entity Framework 4


ShareThis

Scott Guthrie has written a nice post on his blog on Entity Framework. I am sharing an extract of his post.

Found his original Post here: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

.NET 4 ships with a much improved version of Entity Framework (EF) – a data access library that lives in the System.Data.Entity namespace.

When Entity Framework was first introduced with .NET 3.5 SP1, developers provided a lot of feedback on things they thought were incomplete with that first release.  The SQL team did a good job of listening to this feedback, and really focused the EF that ships with .NET 4 on addressing it. 

Some of the big improvements in EF4 include:

  • POCO Support: You can now define entities without requiring base classes or data persistence attributes.
  • Lazy Loading Support: You can now load sub-objects of a model on demand instead of loading them up front.
  • N-Tier Support and Self-Tracking Entities: Handle scenarios where entities flow across tiers or stateless web calls.
  • Better SQL Generation and SPROC support: EF4 executes better SQL, and includes better integration with SPROCs
  • Automatic Pluralization Support: EF4 includes automatic pluralization support of tables (e.g. Categories->Category).
  • Improved Testability: EF4’s object context can now be more easily faked using interfaces.
  • Improved LINQ Operator Support: EF4 now offers full support for LINQ operators.

Visual Studio 2010 also includes much richer EF designer and tooling support. The EF designer in VS 2010 supports both a “database first” development style – where you construct your model layer on a design surface from an existing database.  It also supports a “model first” development style – where you first define your model layer using the design surface, and can then use it to generate database schema from it.

Code-First Development with EF

In addition to supporting a designer-based development workflow, EF4 also enables a more code-centric option which we call “code first development”.  Code-First Development enables a pretty sweet development workflow.  It enables you to:

  • Develop without ever having to open a designer or define an XML mapping file
  • Define your model objects by simply writing “plain old classes” with no base classes required
  • Use a “convention over configuration” approach that enables database persistence without explicitly configuring anything
  • Optionally override the convention-based persistence and use a fluent code API to fully customize the persistence mapping

EF’s “code first development” support is currently enabled with a separate download that runs on top of the core EF built-into .NET 4.  CTP4 of this “code-first” library shipped this week and can be downloaded here. 

It works with VS 2010, and you can use it with any .NET 4 project (including both ASP.NET Web Forms and ASP.NET MVC).

 

Found his original Post here: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

Sunday, June 15, 2008

How to get all the (nested ) Inner Exceptions in the chain


ShareThis
Much of the time for a programer, it is more helpful to know about the inner exceptions occurred while performing a certain operation. In c# its much easy but less utilized technique for getting all the nested exceptions occurred. Getting all the exceptions is also more helpful in error logging and debugging. Below is the technique defined...

try
{
// the target code that might raise exceptions
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}

// output or save the full error message based on your case
//Response.Write (errorMessage); //or
// Console.WriteLine(errorMessage);
}

Friday, June 13, 2008

LINQ to SQL Samples- Must Read


ShareThis
I found this good repository of samples on MSDN on the topic : LINQ to SQL Samples
Useful for the beginners willing to learn LING.

http://msdn.microsoft.com/en-us/vbasic/bb688085.aspx

LINQ is Languages Integrated Query that has been ported with Dot Net Framework 3+ and is a part of Visual Studio 2008.

Here is an another introductory article from about.com on LINQ and XML
http://visualbasic.about.com/od/learnvbnet/a/LVBE_L6.htm?nl=1

String Formating


ShareThis
String Formating has been quite useful and everyday occurring task in a programmers' life.

I have fond many useful reference out there on the web. I am sharing some of them here and will be updating this same post when I find any useful reference for this same topic.

Best place on MSDN for learning about String Formating
http://msdn.microsoft.com/en-us/library/aa720089(VS.71).aspx

Standard Numeric Format Strings
http://msdn.microsoft.com/en-us/library/aa720653.aspx

NET Format String 101
http://blogs.msdn.com/kathykam/archive/2006/03/29/564426.aspx

Good String Handling Description and reference blog:
http://blog.stevex.net/index.php/string-formatting-in-csharp/

Sunday, June 8, 2008

Design Guidelines for Exceptions


ShareThis
http://msdn.microsoft.com/en-us/library/ms229014(VS.80).aspx