Does nHibernate allow drag and drop automatic class creation like linq to sql? - nhibernate

Just a basic question. Learning Linq to SQL and some nHibernate. I am using the mvc tutorial and they drag and drop tables onto the visual studio designer to create the classes and wire up everything.
When I experimented with nHibernate I had to do lots with xml files. Does nHibernate have anything that is "easy" like Linq to SQL or is this drag and drop for Linq to SQL so basic that when I want to do something "real" it won't matter that Visual Studio does this for me (at this basic level)? In other words, the further I go with Linq to SQL, I'll eventually have to handle config files like I do with nHibernate.

Look at Castle's ActiveRecord framework. It replaces the use of XML config files with the use of Attributes directly on the class/property declaration. Also, a tool called ActiveWriter integrates with Visual Studio and allows connecting to a data source and generating the object model!

There is no "native" support like you see with LINQ to SQL. However, there are third party add-ins that will allow you to do something similar with nHibernate. My favorite is this one:
http://sourceforge.net/projects/nhibernateaddin
To use it:
Create a data connection to a
database that contains the structure
you are going to code against (your
development database).
Add a new NHibernate plug-in item
(via add new item) to your project
that will contain you domain objects.
In the property window add the data
connection string from the data
connection you just created (this
isn't automated yet).
Finally, you drag and drop your tables
from your data connection to the
NHibernate plug-in object and when
saved your mapping files and you
domain objects are generated. To use
it you create a data connection to a
database that contains the structure
you are going to code against (your
development database).

Related

EDMX generated with ODT/ODAC, context class not showing in Domain Service Class

I am following an msdn walkthrough for creating an RIA services solution with Silverlight. Here is the article link. I have followed at least 4 other articles and found like a dozen more over internet but all of those create edmx from SQL server. In my case, I have to use Oracle in backend, so I have created the data model through Oracle Development Tool, Oracle Provider for .Net.
After generating the edmx and building everything,
I move on to create a domain service class to use the classes in silverlight project, but for some reason the context class doesn't load in the dropdown where it should.
A sample class generated by the edmx looks like this
I have been trying to do this for a week now, and after having been tried for half a dozen times, I need help.
If you are using Visual Studio 2012 have a look here:
http://support.microsoft.com/kb/2745294
In summary:
Open your entity model in the designer (If needed, click in the "white space" of the designer to ensure no objects within the model are selected)
In the Properties window, change the "Code Generation Strategy" from "None" to "Default"
Delete the two ".tt" files that are adjacent to the model, with the assumption that you have not modified these files beyond their original state when the entity model was created. If you have modified these files, then customizations to your entity model will be lost.
Rebuild the project

LINQ to SQL for an existing database

I have a current project that uses LINQ to SQL to create a database and then to work with the data.
I also have another database which already exists and I do not need to create it. Do you know any tool that can generate the data model for my existing database?
Note: my database is pretty flat so I don't need to be worried about complex relations
Thanks in advance;
using visual studio, can't you just create a new .dbml file and point it to your database and then generate all the Object Mappers?
Code Generation in LINQ to SQL:
http://msdn.microsoft.com/en-us/library/bb399400.aspx

SQL in Visual Studio 2010 & LINQ

I'm working on a project which relies on the presence of a number of tables, views and stored procedures. Until now I have built these all in SQL Server Management Studio.
Now I would like to continue to work on them inside of Visual Studio. This will provide the benefit of version control (along with a number of other benefits hopefully).
I have added a new project to my solution and started working on one of the views. When I tried to build the solution it failed as the new project didn't have a server/database associated: Error 1 SQL03006: View: [dbo].[vw_Test2] has an unresolved reference to object [EV870_ACCT_MASTER].
I was able to overcome this by
-creating a dbschema dump using vsdbcmd.exe
-adding the dbschema dump as a reference to my database project
Is this the correct approach?
Now i can see the schema (tables, views, sprocs etc) in the Schema view (I had to enable display of "external elements") and the error message has gone away. Note: I had to reference like: [$(SQLDatabase)].[dbo].[EV870_ACCT_MASTER]
Now I want to know how I can work with these objects that i've scripted. I don't know how to use the new tables, views, sprocs etc (I want to use LINQ). Do i have to run the scripts first? How then if they are "CREATE OBJECT" scripts, will they run in future (presumably they'd fail as the object already exists in the database). Will my project/solution know which objects need updating and update them?
Ultimately want to take it a lot further- my aim is that the solution will be portable and a the server/database will be configurables. Then my tables, views and stored procedures will be created or amended if they don't exist or are out of date. Is this possible?
When I then start working with the views etc using LINQ I want those server/database references to remain dynamic?
I know there are quite a few questions in there but i'm hoping someone will be able to point me in the right direction- there doesn't seem to be much useful documentation online (or that i've stumbled across so far).
Thanks
Lee
Where I work (and the last place I worked) we distribute the sql scripts to create the database along with the app. In sql a version number is stored and when the app is run it checks to see if its version is newer than the number stored in the database. If so then it knows it may need to run some new sql scripts in case there were any schema changes. When this happens, we just run through all the scripts because they are written in a way that running them multiple times won't hurt anything... this way we don't have to worry about tracking which scripts are the new ones. Just check the version number and that's it.
As far as working with this stuff in Visual Studio instead of Management studio, I'm not sure why anyone would want to do that. Depending on what you use for source control you may be able to get hooks for Management Studio, but even if not that doesn't stop you from keeping your sql scripts in source control. And I wouldn't switch from working with my sql files in management studio to visual studio for the benefit of having built in source control any day.

Generating CRUD with entity framework (like DataSets can)

I added am edmx file and a table to my project. How can I get it to generate CRUD operations? I did this in the past where it generated them as stored procs, but cant find the option on the table properties. What did I do wrong?
UPDATE
After fiddling about, I discovered I am confusing my tools. With a DataSet.xsd I can drag a table onto the Dataset Designer and click the *TableName*TableAdapter. If you view the properties window you will see "DeleteCommand, InsertCommand, SelectCommand, UpdateCommand". Is there a way to accomplish this task with Entity Framework too?
(If you have any trouble seeing this you can right click the table in dataset designer > Configure > Advanced options > check "Generate Insert, Update and Delete statements".
Since no one has responded with a method to accomplish the task, then I have to assume the functionality does not exist.

References/walkthroughs for maintaining database schemas with Visual Studio 2010?

I have Visual Studio 2010 Beta 2 and SQL Server 2008 installed. I'm working with a populated database and want to modify various column types. SQL Server Management Studio requires me to drop tables to do this, and get pretty finicky given my moderate level of knowledge of SQL Server.
However, I heard the new database project type supports changing the database schema to the desired format and it will handle creating and running all the scripts to implement the changes.
I've created a VS2010 database project using the existing database as the source, but so far haven't had much luck figuring out the appropriate method to make the changes without getting an error.
As a result, I'm looking for any reference info I can find on using VS2010's capabilities in this area. Any suggestions?
write scripts instead of using the gui. You can use alter table for instance to change a column. Never use a GUI of any kind to create a change to a database table.
Here's a walk through of the new VS2010 "Deploy-SQL" tab in the properties page of web application projects.