There's a saying that investors get rich in bear markets -- they just don't know it at the time. We are definitely in a bear market today, with the S&P 500 down 19% and the Nasdaq Composite down 29% from all-time highs.

When the markets panic, even the most competitively advantaged companies with solid balance sheets and great long-term prospects get marked down to discounted prices. The following three stocks fit that bill today, making them great long-term buys right now.

1. Microsoft

Even the mighty Microsoft (MSFT -0.24%) has sold off hard this year, down some 30% from all-time highs. That's an even greater sell-off than it experienced during the COVID-19 decline!

Meanwhile, Microsoft just raised its dividend by 9.7% this week, and the stock now yields over 1.1%, along with even more shareholder returns via share repurchases.

With its trailing price-to-earnings (P/E) ratio now below 25, it's even cheaper than Apple (AAPL 0.61%). That's striking, especially since Microsoft is projected to grow its earnings at a higher rate than Apple in the years ahead.

That growth is a result of Microsoft's strong software franchises, including the widely used Office and Dynamic software suites, which are crucial for enterprises to function and likely have pricing power.

Meanwhile, Microsoft's Azure cloud infrastructure platform grew 40% last quarter, and appears to have many years of strong growth ahead of it; in fact, a recession might even accelerate cloud adoption among enterprises as they seek efficiencies.

Microsoft actually has a higher bond rating than that of the U.S. government, with a Standard & Poor's AAA rating. Considering Microsoft's earnings yield is higher than the yield on the 10-year Treasury note, with those earnings likely to grow by double digits annually over that period, it's a bargain stock that investors can buy and hold with confidence.

2. ASML Holding

Another all-star business with a beaten-down stock is ASML Holding (ASML -0.03%), which has seen its stock nearly cut in half from its highs. That's a huge drop for a company with a monopoly on extreme ultraviolet lithography (EUV) technology, the key enabler of leading-edge semiconductor production.

ASML still trades for an expensive-looking 33 times earnings, but that's a bit misleading. Because demand for its machines is currently exceeding ASML's own supply, it is shipping machines to customers before it fully certifies the machines. Final certification now happens at customer sites, which enables faster shipment and implementation.

However, ASML can't recognize the revenue until final certification, so its reported revenue and earnings are lower than what it's actually shipping -- but those earnings will be recognized in future periods.

Recently, management said demand was some 40% above its ability to supply. So even if a recession occurs, it likely wouldn't affect ASML's growth for the next couple of years.

Unlike some other semiconductor equipment companies that have a cyclical component to them, EUV demand should see consistent growth this decade. That's because chipmakers will always want to move to the next node and improve power and performance every year. Since that can't happen without EUV technology, more machines should be sold each year this decade.

ASML pays a similar 1.2% dividend to Microsoft, and is also consistently repurchasing stock. That should benefit shareholders over the long term, and why ASML can be bought today and held with confidence.

3. Farfetch

E-commerce stocks have been sold off big this year, as the pandemic tailwinds fade and rising interest rates have especially hurt growth stocks. European luxury goods e-commerce platform Farfetch (FTCH -83.33%) hasn't been spared, down a stunning 86% from its all-time highs. Along with the general market malaise, Farfetch has suffered even more: Its second-largest market, China, is in recession, and the company pulled out of Russia, its third-largest market.

But Farfetch just made a potentially game-changing deal with luxury giant Richemont (CFRUY 0.34%), parent company of many of the world's biggest luxury brands, as well as owner of Farfetch competitor Yoox Net-a-Porter (YNAP).

As part of the deal, Richemont is exchanging almost half of YNAP to Farfetch in return for a 10% stake in Farfetch, with an option for Farfetch to buy all of YNAP in five years. Most importantly, Richemont will make all of its brands available on Farfetch's marketplace, and will also use Farfetch's back-end platform to power its luxury brands' websites. That could double Farfetch's business in short order.

When the owner of your largest competitor basically admits it can't compete, switches to your product, and then takes a stake in your company, that's probably a good sign.

Farfetch is riskier than Microsoft or ASML because it doesn't pay dividends and isn't profitable yet. However, it has good unit economics, with a 32% contribution margin (gross margin minus demand marketing costs), and management says it expects to be breakeven on the basis of earnings before interest, taxes, depreciation, and amortization (EBITDA) by the end of this year.

With just a low single-digit market share of the global luxury industry, Farfetch has a lot of growth ahead since it seems to be consolidating the online luxury market for itself. It's another great buy-and-hold stock in this bear market.