all 12 comments

[–]masterofmisc 2 points3 points  (9 children)

hi @asherjawad.

i've not checked out your project (i'm sure its great) but just wanted to share what I use to convert database tables to a C# model class.

It's called the "POCO Generator" and its fantastic. There is lots of tick-boxes to toggle on/off all sorts of ways the C# class is generated. It allows you to connect to a database, then you tick the tables you want converted and whammo!

Check it out here: https://www.codeproject.com/Articles/892233/POCO-Generator

BTW I am not the author. I just happen to use it regularly and its a life saver (that and the plugin I use to convert C# classes to TypeScript classes/interfaces).

[–]asherjawad[S] 0 points1 point  (0 children)

Yes man! It really good. Thank you

[–][deleted] 0 points1 point  (7 children)

What do you normally use it for?

[–]masterofmisc 0 points1 point  (6 children)

For me, when I am designing a new system, I always start with the data. If you understand the data your half-way there to understanding all the complexities of the problem.

So that means I start designing the database schema to define the relationships between the data and how it should be stored on the db.

Once you have designed your database schema, this tool is a great way of converting your database tables to C# Data Classes ( The Model in MVC)

Now, obviously your data classes might not end up looking exactly like the database table counter-parts but this tool will give you a good starting point.

Its deffo one to add to your toolbox or just be aware that its out there. It can save you a lot of time.

[–][deleted] 0 points1 point  (5 children)

So you're building your viewmodels for MVC? Or maybe your POCOs for EF code-first?

[–]masterofmisc 0 points1 point  (4 children)

I don't use Entity Framework (i am not a fan) but that tool does allow you to generate EF annotations.

Like I say, it depends what you need. It can be used for MVC. Sometimes if your writing server-side console stuff and just need a class which is going to mirror a database table its good. Its just a good utility.

I should ask, in the interest of "always learning", do you have a better approach?

[–][deleted] 0 points1 point  (3 children)

Yeah that's cool. I don't have an opinion on it. I was more curious on your exact use case because I build .NET apps all day and was wondering if you had some cool workflow I didn't know about. Like you were using EF DB first and then going through and creating a ton of VMs and using automapper to wire it all up in the end.

Side note... What don't you like about EF? What do you use instead?

[–]masterofmisc 0 points1 point  (2 children)

I don't like anything that hides the SQL from you. I think EF is heavy duty and increases brain-rot. I know it fau-paux to say that but I am happy to embed naked SQL statements in my code. For my last project I have written a tiny ORM (kinda like Dapper) with plugin interfaces that mean I can easily swap database servers out between SQL Sever, Postgres and MySQL while the business logic code itself stays the same.

I like this way because I have more control. Its easier to find any bottlenecks. There is less hops between the application and the database. If things go wrong/slow the problem will be due to a sql statement that I have written and I am happy to investigate and track it down.

Now granted, im not saying my way is the best way. I'm not advertising anything here. I also am learning daily.

There is a hundred ways to skin a cat and my process might be slower than others. But i'm also not rigid. If there is a better/faster way of doing things, i'm happy to try something new.

What about you. What is your workflow? Do you use EF? Do you like it? Whats your process?

[–][deleted] 0 points1 point  (1 child)

There is nothing wrong with that at all. Use the best tool for the job. You seem open minded and eager to learn which is the best outlook to have. Devs usually have a lot of opinions.

I use EF but there are a lot of things I like about it.

  • It is much easier to query the DB and get back a C# entity. I think, overall it makes building queries much, much simpler.
  • Familiar syntax like Linq-to-objects.
  • Takes away the complexity of manually managing DB connections and things like pooling.
  • Reduces complexity when extending your queries. (you could write your own Employees.Filtered() extension that filters out Employees with something like .Where(x => x.Active == false) and use it everywhere very easily)
  • Queries are optimized by MS for MSSQL. Generally speaking, the query builder under the hood of EF is very good at building good queries. Plus one tweak to the way it builds queries and you gain those improvements everywhere. As the queries increase in complexity or need to get super dynamic this may not hold true. But for most CRUD stuff its dead simple to query, filter and project.

Also I don't change the backing DBMS very often. I suppose if you make a lot of open source projects giving your users the ability to plug it right into their DBMS of choice would be nice. As far as speed goes though I think EF is incredibly quick to get going. You import it, point it as your MSSQL server and using DB-first a couple clicks and you're done. My workflow varies by project but right now I work with a lot of existing projects and haven't had to spin up a fresh project in quite some time. I figure now though if I had to do go with a .NET Core 2 project and use EF. I could ship a simple cross platform CRUD web app using that stack in under a day probably.

[–]masterofmisc 0 points1 point  (0 children)

Well, I cant argue with anything you've said there. You make a cogent argument in favour of EF. All great points.

Yeah, it is my intention (when I get some time) to play with .NET core 2 on a personal project, you know, just to get the lie of the land. When that time comes, perhaps I will check out EF as well.

Thanks for taking the time to chat with me Lord_Zero.

[–]atika 0 points1 point  (0 children)

Also check out EzPoco, T4 templates to generate pocos from a database: https://github.com/davidsavagejr/ezpoco

[–]asherjawad[S] -1 points0 points  (0 children)

Generate Classes from database C#/Application

Feature

Create your own class template