FluentNHibernate: Getting the Examples.FirstProject to work - fluent-nhibernate

Im trying to get the most basic of examples to run in FnH. I started with the Examples.FirstProject. However, I did not use the SQL lite configuration. Instead, I set the configuration to SQL2005 and created the tables as was diagramed in the example.
When stepping through the code, there appears to be no problems when creating the session factory. I do receive an error however when the code reaches the "transaction.commit" line. The error reads:
Could not insert collection: [Examples.FirstProject.Entities.Store.Products#5][SQL:SQL not available]
Im wondering if there was an issue with the way the tables were created in SQL Server. The IDs were "int" type and the names and such were "varchar(50)." I set the PK of Store, Product, and Employee to its respective ID field. I also made the ID increment automatically by 1 (IdentitySpecification column property in SQL Server). StoreProduct is the many-to-many and is also there per the diagram.
Any help would be appreciated. Thanks.

Have you modified the sample in any way other than changing the database provide? Have you been able to save any entities from the sample (ie if you remove the Products code and just save the Store)?
I developed this sample against SQLExpress, so I would imagine there wouldn't be any incompatibilities with SQL 2005.
Also, this question would probably be better be suited to the Fluent NHibernate mailing list, as Stack Overflow isn't great for these kind-of investigatory postings.

Thank you James. I'll look at using Fluent NHibernate mailing list. As a solution to my issue, I did simplify the example a bit and found that rebuilding the tables helped. In the previous attempt I built the tables in the Database diagram tool. That is where I think something was a little off. Just now I rebuilt them using the menus and still made the foreign key connections with the Database Diagram section. Worked like a charm. Thanks again and keep up the good work with FnH.

First thing to check: Are you sure that you have really created a correct table in SQL server, and that the schema is correct? You can verify this by using SQL Express management studio to view the sql database.

Related

SQL Database running to other computers

I have question about Entity Framework projects or ADO.NET.
How can other users use my project without import SQL database? Is there any method to automatically create database/tables?
Could you please give hints or reference article or something like that.
Thanks,
How can other users use my project without import SQL database?
If you have a project that is just starting a good choise is to use Code First. In this case every developer can use a local database.
Is there any method to automatically create database/tables?
Here comes the good part of Code first - the database will be generated for you. Another thing that helps a lot, in my opinion, is the seeding of test data - Use Code First Migrations to Seed the Database.
Further reading: Migrations
You can use enbedded dbs like derby,h2 etc.

Entity Framework 6 Update from Database ignores deleted columns, type changes

Am I missing something here?
I've a .net 4.5.1 project with an Entity Framework model created from a SQL 2005 database (Connection type is SQL Server also), via "ADO.NET Entity Data Model".
This works fine. That is, until I update the database. If I add new tables or columns to existing tables all is well, but if I delete a column, the update just doesn't work properly. it also throws out errors when I alter the column type.
This same problem was reported a long time ago: http://blog.jongallant.com/2012/08/entity-framework-manual-update.html#.UytNrvldVD0, but it seems so ridiculous I can't believe I am not missing something. Surely I'm doing something wrong? How can I get the model to update properly?
I have the same problem. I opened up the Model, removed the changed tables from the diagram, then Updated from the Database and re-added the tables.
EF brought the table back in again with the correct structure. Save The model, Rebuild the project, everything turns up as expected.
I am not sure why it doesn't detect the deleted columns. I believe there's also issues if you change the data type of the columns, but I've not tested it. But the above solution has worked for me so far.

SQL Server - Checkout system for database objects?

I was wondering if anyone knows any 3rd party tools or existing functionality in SQL Server 2008 so that when someone is working on a table or procedure, it is locked out to that individual. I have searched the net extensively and can't seem to find anything relating to this. We are facing a problem where two people may be working on the same stored procedures and whoever executes last gets the code change! This kind of functionality would come in handy. I think that a lock or check in/check out system would be benefit a project, any ideas?
I am already hooked up to Redgate source control, which does not provide this functionality.
Thanks
Try and have a look at this SO discussion: How do I version my SQL Server database in SVN?
It might not lock things like you want, but it would help to ensure code is recoverable. You could also consider using DDL triggers as some kind of a checking mechanism.
you could try this: http://www.apexsql.com/sql_tools_version.aspx
Alternatively, try this: http://www.red-gate.com/products/sql-development/sql-source-control/entrypage/5-minutes?utm_source=google&utm_medium=cpc&utm_content=unmet_need&utm_campaign=sqlsourcecontrol&gclid=CK_qsPC5prUCFe7MtAodzC8ACA

Can Linq to SQL create a database from DDL files?

Is there anything built into the Linq to SQL libraries that allow me to create an entire database from a collection of DDL files?
Lets say you have a collection of DDL files, one for each table in the database. Conceptually it would be pretty straight forward to call a create table function for each one and each one that succeeds (does not through SQL exception for example due to a relationship or foreign key error) pop the file name off the stack. For any that failed you could try to call the DDL again until it finally succeeded and all of your tables existed in the database ... however ... if there is something like this that already existed in say Linq to SQL or the Migrations project that would be great. Does anyone know if this exists already without having to combine all of the DDL's into a single script? Thanks in advance.
If you have Visual Studio 2008 or 2010 Professional or Above, it includes the new version of database projects. Which can handle that precisely for you (it will even validate the scripts before execution so you can see what errors exists).
I don't believe so. Linq-to-Sql is not really made for manipulating database schemas. You might have more luck with something like the Microsoft SMO libraries.
Use ADO.NET commands instead for that. That should be able to handle it, depending how complex each file is. As long as each file has on executable statement, ADO.NET commands may work fine for what you want to do.

can't find SQL code for XSD schema tables

The following snippet below came from a *.xsd (XML Schema built in Visual Studio) file. I'm trying to figure out where the SQL code lives for the data that can be retrieved with these Strongly Typed .NET tables. I looked everywhere, and cannot find it. Only two of the tables match actual table names in my database. Are these primary and foreign keys configured in Visual Studio for this XSD or are these keys found in the SQL database? If I double click the *.xsd, I can see the tables, but I don't know what data is queried from the database unless I use the SQL profiler. If someone can explain, that would be great.
Found this PDF to be the best resource online so far:
http://oreilly.com/catalog/visualstudiohks/chapter/hack49.pdf
Strongly Typed Datasets starts on page 49. The only problem is that it isn't helping me answer the question I had. When I drag a table from the Server Explorer to the *.xsd file, a TableAdaptor gets created with a method called Fill,GetData(). When created manually, this doesn't get created. It also says it automatically updates the web.config file with connection string information. However, the tables I'm trying to figure out don't have this TableAdaptor. The keys don't seem to be related to SQL at all. They are purely based on the Table in the Visual Studio XSD Designer based on columns created there. I'd still like to know how the data is ultimately mapped to SQL and to what tables.