EF4 Beta 2 Kicks It Up a Notch

The ADO.NET team has released an update along with Beta 2 of .NET 4.0 and Visual Studio 2010.  From the looks of it, they got a lot of nifty features in there, obviating the need for an out-of-cycle CTP.  Having briefly scanned the list, what stands out to me is the foreign key support (now the default for entity relations), the improvements to POCO, and generation of complex types from stored procedures.  I can hardly wait to dig in … I just wish I weren’t so busy!

Posted in Technical | 2 Comments

The Joys of Parenting

Whenever I am presented with a new challenge, I like to thoroughly research it. For example, when it came to buying a house, I bought a couple of books and read up on the topic before plunging headlong. I did the same thing when my wife decided to have a baby naturally. We took a course in natural childbirth and read several books on the topic.

When it came to the area of child rearing, we approached the topic with the same gusto, comparing different parenting philosophies. Along the way we discovered a more traditional approach to parenting, which especially appealed to me because it contrasted with what I experienced in my own upbringing. It’s been almost four years since we started to learn and apply this approach, and I thought it might be a good time to reflect on our experience and what we’ve learned along the way.

Experience has taught me that parenting is unlike any other endeavor I have undertaken. When it comes to topics such as software architecture, or personal finance and investing, I can read up on it and apply what I’ve learned fairly quickly. Not so with parenting. Children are, by their very nature, totally unique and almost completely unpredictable. Even if you have a pretty good idea how you want to raise your children, they will continually surprise you, presenting new challenges. Not only that, but healthy children grow up in healthy families that are based on healthy marriages. Children are constantly growing and changing, and parents often must exercise Solomon-like wisdom, avoiding extremes of being too strict or too lax. And husband and wife, while taking on different roles, need to be on the same page about how to deal with these challenges.

It is for these reasons that we wanted to benefit from the experience of generations past while at the same time recognizing recent advances in social science. We also realized that we needed a tremendous amount of support, especially because we do not have extended family living nearby. We have found all these things in the GFI parenting program, which has a strong presence in the Dallas area, offering courses, support groups and various other resources.

We have taken four courses to date: Infant Way, Babyhood Transitions, Toddler Transitions, and Virtuous Way. Even after having taken the courses, we were still fuzzy on how to practically apply what we learned in everyday life. In fact, we even met other couples who took the courses, but who either misapplied the teachings, or completely misunderstood them. Then we met Carla Link. She and her husband Joey have spent many years touring the country, speaking to and counseling literally hundreds of parents and explaining, in very concrete terms, precisely how to apply GFI and what to do with children at various stages of growth and maturity. The fruit of her work is a series of CD’s and written notes on every conceivable topic related to parenting using the principles of GFI. It’s called Mom’s Notes (although it’s also for Dad’s) and is intended for people who have already taken the Virtual Way course.

Shortly after taking our first GFI course we discovered some controversy surrounding the program. However, upon further investigation we discovered much of the criticism reflects conflicting viewpoints in a broader philosophical and cultural divide. We also observed many vindictive personal attacks on the character of the founders of GFI, Gary and Anne Marie Ezzo, which have been thoroughly repudiated and are completely unrelated to the efficacy of the parenting program itself.

I’d like to end this reflection by making perfectly clear that any parenting program, including GFI, is not intended to replace the wisdom and discretion that parents must exercise themselves. I would also like to make clear that we are continually learning how to parent more effectively and fully respect how people choose to raise their own children. We simply wish to share how we’ve benefited from GFI and encourage others to seek ways of becoming better parents. Our children are worth the very best we have to offer.

Posted in Personal | Leave a comment

Who is Improving LINQ to SQL? Plinqo by Code Smith!

A lot of people have lingering doubts about whether to use LINQ to SQL for real-world applications, especially since Microsoft has left it to languish in favor of the new version of the Entity Framework slated for release with .NET 4.0 and Visual Studio 2010. Nevertheless, I have a consulting client, Credit Solutions, that uses LINQ to SQL for their line-of-business web application and has had a very favorable experience working with it. In addition you’ll get better performance using LINQ to SQL (we’ll see how EF4 compares when it comes out).

The bottom line is that LINQ to SQL is a perfectly viable alternative when you can guarantee that the database will be Microsoft SQL Server (2000 or later). It has support for POCO (persistence ignorance), stored procedures, lazy loading, and concurrency management, and it works well with SOA (n-tier) architectures.

The question is, "Who is adding new features to LINQ to SQL?" The answer is a product called Plinqo, created by the makers of the code-generation tool, Code Smith. The purpose of Plinqo is to generate LINQ to SQL entities that replace those created when you add a dbml file to a Visual Studio project. In fact, Plinqo will generate the dbml file for you, placing each entity in a separate .cs file under a common folder. Actually, Plinqo creates two files: one for the code-generated entity, and another for your own custom metadata that will not be overwritten by the code-generator (for example, attributes that can drive a dynamic data web site).

While Plinqo generates code that is better organized and easier to read, its power lies in the extensions it provides, such as manager and query classes, a build-in rules engine, audit trail, caching, cloning and detaching entities. It also de-normalizes many-to-many relationships and takes advantage of improvements to the DataContract attributes for .NET 3.5 SP1 (avoiding cyclic references and the need for the "unidirectional" serialization option). In addition, Plinqo will create enums instead of entities for tables with lookup values.

But wait, there’s more! Plinqo has actually enabled batch updates and deletes, eliminating possible round-trips when calling SubmitChanges to process updated entities. Wow, now that is something I had been hoping Microsoft would give us in the next version. But thanks to Plinqo, I won’t have to hold my breath waiting for Microsoft, which has stopped adding new features to LINQ to SQL. Lastly, Plinqo also enables batch queries and the ability to process multiple result sets from stored procedures.

And to top it off, Plinqo has templates to create an ADO.NET Data Services layer that exposes entities via a REST-ful web service. There’s even a quick start template that will create both the service and a dynamic data web client in a matter of seconds.

So before you decide to give up on LINQ to SQL, check out Plinqo to get a fresh option for using LINQ to SQL in real-world applications. They’re even offering a free CodeSmith license if you mention Plinqo in a blog or tweet.

Posted in Technical | 4 Comments

Why Health Care is Broken

Over the past few years it has become abundantly clear to me that the health care system in America is fundamentally broken. What we have tried to do as a country is build our health care system on capitalist principles. On its face there’s nothing wrong with that approach, if – and this is a BIG if – there are safeguards in place to prevent rampant greed from posing what has come to be called “systemic risks”. What the financial crisis has taught us, if nothing else, is that without sufficient regulation and oversight, a capitalist system that allows greed to run amok is eventually going to break down. And that is precisely what has happened to our health care system.

Capitalism functions on the premise that consumers have a choice over where to spend their money and competition exists to keep prices reasonable. But in the case of a necessary medical procedure, you just can’t call around to get the best price for what needs to be done. Instead you go into a hospital or doctor’s office, have a treatment and then get the bill. The provider basically gets to charge you whatever they want, and there is no real competition to keep prices down.

Here is an interesting example. About a year ago my wife had some pre-natal blood work done. For one reason or another, our insurance company would not cover the procedure. Not only would they not cover it, but they would not even give us an EOB (explanation of benefits) stating the amounts we are required to pay based on the rates that the lab has negotiated with the insurance company. The lab charged us about $1000 for the blood analysis. However, I found out from my current insurer that the price reimbursed to them would have been just $200. That’s a 500% markup for people without proper health insurance! Of course, with health insurance we would pay even less than that.

Then last November I went to the ER complaining of stomach pain. Eventually my doctor ordered a CT scan. The price of the scan to someone without insurance? $6000 for a 6 minute test – that’s $1000 per minute! The price to someone with insurance? Just $1000, one sixth the cost.

This is just sheer insanity, the result of unbridled greed. And the system which allows that greed flourish unabated is just plain broken. The main problem we face now is that premiums for health insurance are so high that companies either stop offering it to their workers, or only offer to cover you and not your dependents. That’s my situation currently, and it costs me about $12,000 per year just to cover my wife and two kids.

But what happens when you can’t afford it, or when you’re laid off? If you get caught without insurance and need even non-critical medical care, you’re screwed, plain and simple. A visit to ER will probably set you back several thousand dollars.

Before you throw your hands up in despair and say there’s no other way, know that it doesn’t work this way in most other countries (say in Canada, France or Great Britain). Yes, the government is involved and there are inconveniences. But we’re reaching the point when it doesn’t matter anymore. If things stay the way they are now, hardly any of us will be able to afford health insurance and will face financial ruin in the event of an illness or accident.

The moral of the story? If you don’t have health insurance now, don’t walk but run out and go get some, even if it’s not worth the paper it’s written on. Why? Because even if the insurance won’t cover a procedure, you will pay the negotiated rate between the hospital and the insurance company. Otherwise, you’ll get gouged in a way you never imagined.

Posted in Personal | 4 Comments

The Cost of Obesity

A recent study estimated that obesity costs Americans $147 billion per year, by causing four major diseases: heart disease, diabetes, cancer and stroke. A full one third of Americans are obese. Not a day goes by when I don’t see ads for weight control programs and surgical interventions. But none of these options seems to offer meaningful and lasting weight loss. (I have two siblings who underwent gastric bypass surgery but who regained all the weight they had lost.) Collectively, we are in a massive state of denial about the health implications of being overweight, and many people don’t wake up until the effects of obesity have seriously impacted their health.

One year ago I weighed 235 pounds – 45 pounds more than I do today. I spent the last 5 years at that weight level, which is 70 pounds more than my ideal body weight of 165 pounds. For most of that time I was pretty much oblivious to just how overweight I had become and the health dangers I was exposing myself to. Even though I had started experiencing negative effects on my health, I had become numb to the amount of weight I was carrying, but even more significantly, I felt utterly helpless to do anything about it. It seemed no matter what I did, and how much I dieted and exercised, I was only continuing to gain more and more weight.

Then about one year ago I entered a little-known weight loss program, which resulted in my losing more than half of my excess weight. It includes a flexible food plan with three meals daily. There’s no sugar or flour, and I must weight and measure all my food. I attend three meetings per week and make 3-4 calls each day to other program members for encouragement and support. The nice part is that the program is completely free, because it is just a group of individuals pledged to helping one another overcome their problems with food. Most of the people I see each week have lost 70-100 pounds or more and have kept it off for several years. Members maintain strict anonymity, so I am not at liberty to disclose the name of the organization here. But if you are interested in finding out more, please do not hesitate to contact me.

Posted in Personal | Leave a comment

More on Entity Framework 4.0

DevelopMentor just published an article I wrote on What’s New and Cool in Entity Framework 4.0, where I explain the new support for POCO and n-tier applications in EF 4.0.  Enjoy.

Tony

Posted in Technical | Leave a comment

Top Ten New Features in Entity Framework 4.0

The Entity Framework team at Microsoft has been extremely busy this past year to get a new version of the Entity Framework out the door. The first release (which shipped last summer with .NET 3.5 SP1) generated a fair amount of criticism, especially because it lacked many features present in LINQ to SQL, such as POCO (Plain Old CLR Objects) support, and required developers to write excessive amounts of code to deal with things like concurrency and n-tier scenarios.

In response, the EF team published an Entity Framework Design Blog, soliciting feedback from the community on critical design decisions. The team has also published a series of posts on new features on the ADO.NET Team Blog. We now have the first CTP of EF4 and the MSDN documentation is online.

EF4 comes with a boat load of features, so many in fact that it\’s hard to know where to begin! To help break them down, I have compiled a top-ten list of EF4 features. These are listed in relative order of importance.

  1. Define your own objects that are completely decoupled from persistence concerns.

  2. Create customized code generation templates (for example, POCO classes).

  3. Load related entities automatically on-demand.

  4. Different options for tracking changes to entities.

  5. Propagate entity changes across service boundaries for batch updates.

  6. The tools fix up entity names in case database tables are in plural form (Northwind!).

  7. Create an entity model and generate the database from it.

  8. Create classes without a model.

  9. Have more control over storage, conceptual and mapping schemas.

  10. Miscellaneous Improvements

a. Complex Type Support

Create complex types in your model.

b. Foreign Keys

Optionally include foreign keys in your model.

c. LINQ to Entities Functions and Operators

Call database, conceptual and model-defined functions from L2E queries.

d. Testability Improvements with IObjectSet<T>

Test-driven development is easier now.

e. T-SQL Readability and Performance

Generated SQL is faster, simpler and easier to read.

Hats off to the EF team for responding to almost all our requests. Mapping multiple stored procedure results to complex entities is still not supported, but there has to be something for the next version. 🙂

Posted in Technical | 8 Comments

Smarter Tx Promotion with SQL Server 2008

A while ago I blogged on a gotcha to watch out for when using System.Transactions with SQL Server 2005. Basically, if you open a second connection to SQL Server from inside a using block in which you create a new TransactionScope, SQL Server will automatically promote the transaction to a distributed one in which the Distributed Transaction Coordinator (DTC) manages the transaction with the two-phase commit protocol. While this is a more expensive operation, it\’s exactly what you want if you want to update two databases within the same transaction, such that both will either succeed or get rolled back. However, SQL Server 2005 would promote the transaction to distributed even though both connections are to the same database, using the same connection string! Most of the time, you would wish instead to use a more efficient native transaction, but to do so, you would have to open a single database connection. SQL Server 2008, however, addresses this problem by not promoting the transaction to distributed when multiple connections are open to the same database with the same connection string (i.e., the connections are pooled).\r\n

To verify this, all you have to do is add a watch in the Visual Studio debugger for Transaction.Current, then expand it to the TransactionInformation property, looking at DistributedIdentifier. If it shows up as an empty Guid, the transaction is local; otherwise, it has been promoted to distributed.

Posted in Technical | Leave a comment

Entity Framework Preview

The Entity Framework team just released CTP 1 of the Entity Framework for .NET 4.0 Beta 1. The next version of the Entity Framework has a bunch of cool features a lot of have been clamoring for, such as support for POCO (Plain Old CLR Objects), lazy loading, and n-tier scenarios. The team has also posted a series of walkthroughs you can try out:

  1. Self-Tracking Entities
  2. POCO Templates
  3. Code-Only Design

Enjoy.

Posted in Technical | 2 Comments

LINQ to SQL: It Lives! (sort of)

A lot of people are confused about whether or not they should use LINQ to SQL, because the word on the street is that Microsoft decided to kill it in favor of another ORM stack, the ADO.NET Entity Framework. The truth, however, is that Microsoft has never said they won’t continue to support LINQ to SQL, only that they won’t be investing heavily in advancing the product and adding a lot spiffy new features. I liken the situation with that of Windows Forms versus Windows Presentation Foundation. Windows Forms aren’t going anywhere and will continue to be supported, but Microsoft is not going to invest a whole lot in advancing Windows Forms when WPF is their primary GUI platform.

That is why Damien Guard, a member of the LINQ to SQL / Entity Framework team, posted a list of changes to LINQ to SQL coming with the release of .NET 4.0.

For a lot of situations, LINQ to SQL makes perfect sense. For one thing, it’s a whole lot faster than EF, because it doesn’t have to go through as many query transformation layers. LINQ to Entities starts with an expression tree, that turns into a conceptual command tree, that turns into a store command tree, that turns into native SQL. L2S, on the other hand, starts with an expression tree that’s converted directly into native SQL.

LINQ to SQL is perfectly suited for real-world scenarios, with great support for stored procedures, concurrency, and POCO. I even have a client that uses it to drive their bread-and-butter web application, and they’ve experienced great results with it. EF, on the other hand, will only really be production-ready when version 2 comes out with .NET 4.0.

That said, if you do want to benefit from the tremendous investment Microsoft is making it its data platform, or if you want to be able to use databases other than SQL Server, then Entity Framework is definitely the way to go. Furthermore, EF is more than just an ORM – things like reporting and analysis services will eventually know how to talk to an EF conceptual model.

However, if you have total control over which backend database you will use, and you know that will always be SQL Server, and you want to take advantage of the power, performance and simplicity LINQ to SQL has to offer, then you should not hesitate to use it. It will be around for quite a while … at least as long as Windows Forms. J

Posted in Technical | 2 Comments