I highly doubt they would have swapped your whole engine at a dealer. Car dealers don't go to a lot of trouble to fix cars on their lots. They patch them up if they can, and auction them if they can't. Now, I would run a carfax report on your car to see if it was ever in a major accident.
If your car was in an accident, it is often feasible to replace the engine if you have front end damage. It generally costs about $1500-2200 if you get it done shady.
The engine in the 94 and the 97 was the same 1.6l I-4. If someone was inclined, they could have swapped engines.
Another (cheaper) way to check this is to find someone else that has a 97 Sentra and ask to look under his hood. If your engine looks different (the plastics and badging), then your suspicions are confirmed.
I gave my '97 Nissan sentra (113 k miles) to a mechanic to get the Timing chain kit replaced. He initially bought a kit that is designed for 1995 - '99 Nissan sentras. But, quoting that it is not fitting, he replaced that with another kit. I researched a little and was shocked that it was listed under the parts needed for 1991 - 1994 Nissan sentra. (The parts that I am buying are not NISSAN parts and I bought this car from a dealer @ 83 k miles)
My question is:
1) Can the parts listed under 1994 engine parts fit for my car ('97)?
2) Was my engine changed and a '94 model engine installed even before I bought the car?
I would appreciate any answer.