i've created a database in sql server. After that, i choose to use Entity Framework for the first time of my life. Reading a few posts here, i used the Reverse Engine Code First and it created all my models from my database. Works great, but always when i'm trying to understand a problem, peoples says about the edmx, which i dont have. Why?
What is the real best way to design a database first and use the EF after?
For example, i dont know how to update my models after changing the base. I always need to run the Reverse Engine Code First Tool again, wich messed with a lot of other things.
I'm really loose, and sorry for this post if has another one equals. I tried to search but dont know the right terms to search. Its my first time with EF5.
Thanks
EDMX files are used when you have Database First and want to use as ADO Dataset.
Related
I am trying to understand some basics of Lucene, the full text search engine. More specifically I am looking at Lucene.Net.
Today I have an old legacy .NET 4.8 web app. Some is MVC, but the newer parts follow a pretty nice API first pattern. The app holds a lot of records (app half a million) with tons of different fields. The search functionality there is outdated to say the least. It is a ton of old Linq2SQL queries that fan out in like queries.
I would like to introduce a new and better way to search records, so I started looking at Lucene.Net. But I am trying to understand one key concept, and I can't seem to find the answer anywhere, and I think it might be because it cannot be done, but I would like to make sure.
Is it possible to set up Lucene to monitor a SQL table or view so I don't have to maintain the Lucene index from within my code. The code of this app does not lend itself to easily keeping a Lucene index updated when things are added, changed or deleted. But the database is good source of truth. I can live with a small delay on having the index up to date. But basically I would like define for each business model what fields are part of the index and what the id is, and then be able to query with that index from the C# server side code of my Web App.
Is such a scenario even possible or am I asking too much?
It's totally possible, but not out of the box. You have to implement it if you want it. Fundamentally you need to implement three things.
A way to know every time a piece of relevant data in the sql database changes
A place to capture information about that change, call it a change log.
A routine that reads the change log, applies those changes to the
LuceneNet index and than marks the record in the change log has processed.
There are of course lots of different ways to handle each of these.
This SO answer Lucene.Net index updates, when a manual change is done in SQL Database provides more details on one way this can be accomplished.
I'm trying to set up Entity Framework 6 in my project to facilitate the programming. However, I'm facing some kind of weird trouble.
I tried to follow this tutorial but with my own DB. http://www.aspsnippets.com/Articles/Simple-Entity-Framework-Tutorial-in-ASPNet-Web-Forms-with-example.aspx
As I tried to create an ADO Entity Data Model, everything worked fine and I got my model done. I'm able to see it in the model explorer. However, I'm not getting anything in my "Models" folder, and I cannot add a reference to my model in my using statements.
Which makes me not able to create the kind of functions as described in the tutorial.
Has anyone a clue about how to solve this?
Using EF with Database First or EDMX First will hold you back while learning Entity Framework. The best way to learn it is from the ground up, using Code First. DB or EDMX First only really come into play when you're reverse engineering old databases, and even in these cases, you'd be better to rewrite the database in Code First and phase out the old one.
There is a really good tutorial I've found here: Entity Framework Code First End to End. It teaches best practices, as well as going into detail about how and why it all works. It's one of the best ways you can spend 75 minutes when learning Entity Framework.
Start off small, and build outwards. In EF7, they are phasing out the EDMX, so even when working with Database First, you'll need to know everything about Code First in order to make it all work properly. The scaffolded code generated by Database First is really badly written, and needs refactoring as soon as it lands. You'll be refactoring and adapting the code anyway, so Code First is,in most cases, more straightforward.
Basically I have made a MVC3 application that connects to and updates a database that exsists on a server. This database is a test one however, and when I roll out the project live I need it to connect to the actual database. My question is how hard would it be to change the project/application to point at this new database?
I used the database first method, and am aware I would need to change my connection string. I feel it is unlikely to be as simple as that.
Any help, tips or tutorials would be greatly appreciated.
As long as the database structures are the same, it is just as simple as that.
You just need to change the connection string.
Additionaly if you would like to deploy 2 versions of the website, each using it's own connection strings (for example for developpement and production) you can create 2 web.config files. Refer to this link SO question
It shouldn't be that hard. You just need to make sure that the database that you are working on now and the database that you are changing to are equal in table names and column names otherwise you are going to have configure it to use the new database tables and columns.
This questions actually refers to another one already asked, now I want to reformulate it :)
My issue is: There is an online shop running on MySQL database, hosted somewehre on the internet. Now I'd like to do some administration stuff from my C# application.
What I want to do: All I want is to run SQL-queries on that database and get the results as entities in my application so I can browse through them like through normal Lists/Classes and then post back the changes to the database. The problem is not the connection to the database - it works fine (using SSH and Connector/NET driver) - but the question, how to turn the SQL-results into C# classes.
I had a closer look at Fluent NHibernate and SubSonic, but I still can't figure out which one suits best or - even worse - if these are really the right approaches to my problem.
So I don't want to build an application which stores its own data in a database but gets the data it needs from a public database.
I hope I could make myself more clear this time :)
Thanks in advance!
ORM is definitely the way to, because it allows you to abstract your data access.
You may find a code generator helpful (to avoid the repetitive task of writing the classes and all their properties): NHibernate Code Generation.
This way you can still use classic NHibernae instead of Fluent Hibernate, which by the way looks pretty useful.
Im having a really hard time figuring out how to specify a good search term for my problem: separation of gui and database interaction in visual studio 2008 using Linq to sql.
According to my teacher in a c# class im taking it's not correct to let the GUI be dependant on a specific way of getting data.
The way my project is currently set up is that we have a mssql database where everything is stored.
The solution is split into 4 seperate projects. UserGUI, AdminGUI, Logic and Db.
Now using linq to populate listboxes and similar things I use something like:
From the windows form in the project UserGUI:
//The activeReservationBindingSource has Db.ActiveReservation as it's value
private void refreshReservation() {
activeReservationBindingSource.DataSource = logic.getActiveReservationsQry();
}
To the Logic project:
public IQueryable getActiveReservationsQry() {
return dbOperations.getActiveReservationsQry(this.currentMemberId);
}
To the database project:
public IQueryable getActiveReservationsQry(int memberId) {
var qry =
from active in db.ActiveReservations
where active.memberId == memberId
orderby active.reservationId
select active;
return qry;
}
This makes sense to me seing as I can send items from listboxes all the way to the database project and there easily update/insert things into the mssql database. The problem is that it would be pretty hard to merge over from a mssql database to lets say an access version.
What should I be reading up on to understand how to do this correctly? Is creating my own classes with the same values as the ones visual studio generates for me when I create the dbml file a way to go? Should I then in the logic project populate for example List that I pass to the GUI? To me it seams like "double work" but perhaps it's the correct way to go?
Be adviced that we have not read anything about design patterns or business logic which seems to be a pretty big subject which im looking forward to exploring outside the frame of the course at a later time.
I was also thinking that IQueryable inherits from IEnumerable and perhaps that was the way to go but I have failed to find any information that made sense to me on how to actually accomplish this.
The GUI also knows about the datasources which I think is a bad thing but can't figure out how to get rid of.
Please understand that I tried to figure this out with my teacher for half an hour today at the only tutoring available for this project and then spent most of the day trying to find similar answers on google, SO and from classmates without any result.
There's a post here that I answered where the question was a bit similar to yours. I think it worth to take a look.
Regards
One keyword to read up on: Model-View-Controller. That's kind of the idea you're after. Your "View" is the GUI. The "Model" is the data layer, and the Controller is the code that takes data from the DB and hands it to the GUI (and vice-versa.)
Check out the repository pattern. There are several implementations you can find by googling "Linq repository."
you may want to check out the MVC Storefront series here: http://www.asp.net/learn/mvc-videos/#MVCStorefrontStarterKit. In the series, Rob Conery builds a Linq IQueryable repository that returns custom made objects instead of the linq objects.
May be you can take a look at Data Abstract
According to my teacher in a c# class im taking it's not correct to let the GUI be dependant on a specific way of getting data.
Honestly your teacher is an idiot. This is one of the stupidest statements, from a database perspective, I've ever read. Of course you want to be dependant on a specific way of getting data if that is the most performant way to get the data (which is almost always database specific and means not using LINQ to SQL for complex queries but that is another who issue). Users care about performance not database independence.
Very few real world applications truly need to be database independant. Yes a few kinds of box software sold commercially are (although I think this is usually a mistake and one reason why every commercial product I've ever used is badly designed and horribly slow).
And since every database implements SQl differntly, even using ANSII sql is not completely database independant. Access in particular is no where near close to the ANSII standard. There is no way to write code which will work correctly on every single possible database.