Question

I need to compare what's on my POCO classes against my database. I am currently using Microsoft Roslyn and Microsoft.SqlServer.SMO and comparing the data, in my opinion, 'roughly'. It's working perfectly, but I was wondering if there was a better way to do so.

Today I have to compile the file using Roslyn, load the database info and compare what I want.

Let's say I have this POCO file:

[Table("XPTO", Schema="ASD")]
public class MyPoco 
{
    public int PropId {get; set;}
    public virtual Prop Prop {get; set;}
    public DateTime? MyDate {get; set;}
}

And I also have the Table info. I want to see if what is nullable in my POCO class (MyDate) is nullable on my database and vice-versa. I want to see if my database has a Foreign Key to table Props and if it is not-nullable as in my POCO.

As I said, it's already working today, I just wanted to rewrite the code to use a more effective way to even maintain.

Does EntityFramework provide some sort of API or anything?

System Info

SQL Server 2008 R2
Entity Framework 4.1
C# 4.0

Thanks();

Was it helpful?

Solution

If I'm reading your question right - you'd want some API to fetch the relationshiops and other metadata information from the DbContext or EF/code-first at runtime?

The best I've seen so far - and the best the two of us could do was this...

How I can read EF DbContext metadata programmatically?

...take a look if this can help you...

And you're welcome to post there if you happen to come into possession of some new and vital piece of information (we made it with the intention to serve as a one-stop question for subjects like this).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top