Converting SQL Procedure to LINQ


I'm a bit panicked trying to do a major change from an internet cafe on my vacation - so pls excuse simplicity of request -

Need to transfer the following sql query to Linq:

		WHEN CourseInstance>1 THEN 
				Name + 
				+ ' - '  + 
				CAST(Year(RegisterDate) AS varchar(4))+ '-' + 
				CAST(Month(RegisterDate) AS varchar(2)) 
			ELSE Name 
	END AS Course,
FROM    Enrollments

Open in new window

I have created a repository and am making modifications to it in following:

 public IEnumerable<Enrollment> GetEnrollmentsByUserName(string userName)
            return DbSet.Where(e => e.UserName == userName); ????????????????????


Open in new window

Any help in translating the query from the top to the area with the question marks below   greatly appreciated!

Frozen Brain
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

var query = 
from e in Enrollments
select new { Id = e.Id, Course = e.CourseInstance > 1 ? e.Name + " - " + e.RegisterDate.Value.Year.ToString() + "-" + e.RegisterDate.Value.Month.ToString() : e.Name } ;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RBSAuthor Commented:
Excellent - thanks!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.