.net mvc3 mysql table without primary keys - mysql

I am new to .net and the only experience I have is with an MVC3 Entity Framework Code First project. I need to write a new web app that will query an existing legacy database. I have read only access to this MYSQL database. Most tables have no primary keys. I can connect to the DB okay. When trying to wire things up with EF and pull some data , I get errors that the the tables have no primary keys. Researching this issue on the web has brought me to the conclusion that I probably cannot use EF in this case. Given my limited experience, what would be my next best course of action? Any assistance would be appreciated.
Kindest Regards.

You could use ADO.NET, which is built into the .NET framework. It will mean that you will have to write SQL code to interact with the database.
To get ADO.NET to work with MySQL, you'll need the MySQL ADO.NET connector. More documentation on ADO.NET can be found on MSDN.

Given the read only access to a DB without primary keys, Entity Framework won't help you. I haven't tried it by myself, but I suggest you try using XSD files to create tableadapters and tables for your mysql pendants. But even if this works, without keys you won't be able to add any associations.

Related

Entity Framework Migrations - The underlying provider does not support the type 'nvarchar(max)'

I am converting my C# asp site to use a mysql db instead of the local db that the project is first built with. I am using two dbs, one for the built in account functionality, and one for the functionality that I have added.
The problem I have is that when the second db is seeding, I get the following message:
The underlying provider does not support the type 'nvarchar(max)'.
I'm assuming this is due to MS syntax that works with the .mdf db, but doesn't work with MySQL?
How do I go about solving this?

Not possible using NHibernate?

I am new learner to NHibernate. I am trying out samples with MSSQL database. We all know query using MSSQL is different from MYSQL database. If i need to use this sample for MYSQL, do i need to change anything other than configuration settings? Also i need to know is there anything that is not possible because of NHibernate?
There are multiple ways of configuring NHibernate.
What you need to set is called:
The dialect is responsible for converting IQueryable, ICriteria or so called HQL (hibernate query language) to the SQL of the corresponding database.
But if you want to have this general, you must pay attention to the ID (in some cases even use locking). SQL has so called auto-identity, while Oracle works with sequencers. But NHibernate has it's own ways of generating identity.
I would advise you to:
use latest NHibernate (not older than 3.3.x.x)
try out fluent nhibernate mapping
eventually find some example on nhibernate + fluent + unity/structure map (DI framework) - mostly you find something related to DDD projects

grails/gorm/mysql/hibernate

I have a simples question. I have been trying to learn Grails by my own, and i managed to do a simple application using Grails/Gorm.
1 ) Later, i decided to use Mysql instead of Gorm - i just needed to configure the 'DataSource' and download the driver.
2 )So if i want to use hibernate between both (Grails and MYSQL) like this:
http://www.grails.org/doc/latest/guide/15.%20Grails%20and%20Hibernate.html, i need to make an 'hibernate.cfg.xml' file, and specify my mysql database url, user, pw etc .. and i have to map each Class in Grails for MySql columns.
So what is the diference between 1) and 2) ? and what exactly hibernate does. Give examples if possible
PS. Please correct me if i said something wrong, im kinda new to this
I think you are a bit confused here.
GORM is not a database, it is a ORM that maps you Groovy classes to database tables. It uses Hibernate under the covers to achieve this (Hibernate is also an ORM).
The default database Grails uses is an in-memory HSQL DB. If you want to use MySQL instead of that, all you need to do is change the settings in conf/DataSource.groovy.
You don't need to create any Hibernate xml files. That part of the documentation you've linked to is to allow people with existing Hibernate domain models to easily re-use them.
Hope this helps clear things up.
cheers
Lee

Web application using Hibernate+MySql

i was asked to do a book manager at university with hibernate and mysql. I have a simple question. If i choose to do a web application, grails already uses hibernate. GORM runns over hibernate. so to use mysql i only need to configure jdbc grails drivers and that's it?
i mean, "for the project you must use hibernate and mysql" - this are the requirements. So can i do that way?
thanks in advance,
JM
Yes, of course you can.
You'll need to get the MySQL JDBC driver from this location.
Grails? When you're new to programming? Whose idea was this?
Personally, I think that taking on all these unknowns is risky for someone who's "new to programming." Do you know anything about SQL or JDBC? Have you ever written a web project before? This could be difficult.
I don't know how to be more specific. Download the JDBC JAR from the link I gave you.
I'd recommend that you start with a JDBC tutorial first. Hibernate is not for you - yet.
Hibernate is an object-relational mapping tool (ORM). It's a technology that lets you associate information in relational database tables to objects in your middle tier. So if you have a PERSON table with columns id, first, and last Hibernate will let you associate those data with the private data members in your Person Java class.
That sounds easy, but it gets complicated quickly. Your relational and object models might have one-to-many and many-to-many relationships; Hibernate can help with those. Lazy loading, caching, etc. can be managed by Hibernate.
But it comes at a cost. And it can be difficult if you aren't familiar with it.
If you have a deadline, I'd recommend creating a Java POJO interface for your persistence classes and doing the first implementation using JDBC. If you want to swap it out for Hibernate later on you can do it without affecting clients, but you'll have a chance of making progress without Hibernate that way.

LINQtoSQL Not saving to database,but changes show in app

Hey all, I have a linq app using C# express2008 and sqlserver express 2005 (mdf file connection)
I followed the regular dml generation and vanilla datacontext. However i created a repository class to manage the Linq stuff.
In using the functions, selecting data works fine, updating data works in the app.But when i check the data in the tables, nothing has changed.Needless to say, when i close the app, also no change.
I used SQL profiler to see what was being sent to sqlserver express, nothing showed up.
What could be my issues?
Are you calling SubmitChanges() on the DataContext?
No primary key, or no column(s) in the L2S model marked as primary key member(s)..?
Ok... found 'a' soln.
1. changed (forced) default connection string from looking at a file to an instance of sql serverĀ (using database instead of file)
2. Attached file to sql server express..and renamed the db.
Ran app again and everything works. Only thing is..the dml still uses the old connection string..so any mods to tables have to be done in sqlserver.
This is just my quicky patch, anyone care to provide a more elaborate view?