MVC with InterSystems Caché ODBMS Backend - c#

I've been looking into using and MVC C# frontend to a Caché database backend. After looking around for a while i haven't been able to find an effective way of connecting the two together (via .edmx model generation). I know I'll need a database driver for Visual Studio 2012 to do this but i don't know where to find it.
I've been developing a few apps using MVC technology and want to keep following suit instead of resorting to using their .csp based technology.
Hopefully somebody can help with this.

Take a look at the Cache Managed Provider for .NET documentation:
http://docs.intersystems.com/cache20121/csp/docbook/DocBook.UI.Page.cls?KEY=GBMP
The Managed Provider functionality specifically allows you to access Cache data from within .NET programs. It's not going to be as nice as using, say, the .NET Entity Framework to do data access, plus you'll have to take InterSystems' code example with a grain of salt since they are pretty simplistic, but this should be what you need.

You can use an ORM framework like Entity Framework or NHibernate to get access to Intersystems Cache so the database can be separated nicely in the data layer. I managed to make NHibernate works with Intersystems Cache works. Have a look at here if you are interested.

Related

Best practise for SQL in .NET project

I'm a very beginner in .NET and now I'm developing a little project (web API) using NancyFX framework. In my project, I need to use SQL database for some very basic tasks like storing registered users' details or getting some user information. I'd like to know what is the most popular, convenient and modern way of using SQL in .NET for beginners? I mean, should I use LINQ or just pure SQLClient functionality or are there any good libraries for working with SQL on .NET? I've tried to implement LINQ to SQL pattern but ended up with huge chunks of unused auto generated code and even bigger mess in my head...
For a framework to communicate with you're database I would recommend using Entity framework, its very convenient and easy and has the Code first approach which you should read about.
More over i suggest you follow the repository pattern,
https://msdn.microsoft.com/en-us/library/ff649690.aspx
This basically means - each object you save in the db, will have a repository which will contain all the object of its kind and that will be you're entry point to reading/inserting/updatibg/and deleting rows from the db, while abstracting away all details of implementation - in our case I recommend entity framework as I mentioned before.
Good luck

Designing data access for Compact Framework and Full Framework

We currently have a desktop app which uses data from SQL CE. We used Entity Framework for our ORM layer to the database and all data access methods are built around this.
Now we have to build a smaller scaled down "clone" of this app for Windows CE 6.0 on the Compact Framework, also using the same SQL CE database design as on the desktop version. The problem is that compact framework does not support Entity Framework, so we are forced to access the database the old fashioned way (ADO.net, datasets, etc). However this is causing duplication of our whole data access layer and maintenance on these two apps looks like it can turn into a nightmare.
Ideally I would like to switch to the lowest common denominator that will work for both platforms - with current information I guess that means using old ADO.net will be the way to go, compiled into a separate assembly, but I just wanted to ask if anybody here has any other suggestions, or have perhaps faced a similar situation? Are there any good alternatives to EF that could work on both compact and full framework?
We use the OpenNETCF ORM in Windows CE (backed with SQLCE), Desktop (backed with SQLCE) and Android (backed with SQLite) which uses nearly identical code for all three. I say "nearly" because the data store initialization code differs between them (target file name, where to store it, etc). You could pretty easily add a full SQL Server implementation as well - it's probably a near 1:1 copy of the SQLite stuff. I've never done it simply becasue I've not needed it.
See Also: Is there any FREE ORM for .NET Compact Framework (Windows Mobile 6.1, SQLServerCE)?
Another Option: http://sqlite.phxsoftware.com/
Yet Another Option: http://www.db4o.com/s/compactframeworkdb.aspx

Are there existing data layers I can use for an application I'm building?

I'm writing a .NET application and the thought of implementing a data layer from scratch is icky to me. (By data layer I'm referring to the code that talks to the database, not the layer which abstracts the database access into domain objects [sometimes called the data access layer and used interchangeably with data layer].)
I'd like to find an existing generic data layer implementation which provides standard crud functionality, error handling, connection management - the works. I'll be talking to SQL Server only.
It doesn't matter to me if the library is in C# or VB.NET and I don't care if it's LINQ or ADO.NET. As long as it works.
** I want to emphasize that I'm not looking for data access technologies or mechanisms (e.g. LINQ, ORM tools, etc.) but rather existing libraries.)
If you are talking to only SQL Server the Linq to SQL is your best option. It is pretty easy to get up and running. You will get both the Data Layer and the Abstraction. All you have to do is provide a connection string to Linq to SQL and it will handle the rest.
If you are going to connect to other database than SQL you would want to with NHibernate.
NHibernate takes a little more work than Linq to SQL to get up and running. MS provided in Visual Studio a nice tool that can get you reading from a SQL database pretty quick.
Honestly as much of a fan as I've always been with NHibernate. With the latest release of Enterprise Library 5 Data Access Block that they added in the dynamic mapping support natively. I would have to strongly consider not using NHibernate on a project and instead use a forward database generation tool from my domain objects to create my database (perhaps even use NHibernate solely for the scheme export) or something like CodeSmith and use EntLib.
You can use easyobjects has a very small learning curve, and is very extensible.
From their web:
EasyObjects.NET is a powerful data-access architecture for the .NET Framework. When used in combination with code generation, you can create, from scratch, a complete data layer for your application in minutes.
I'd like to find an existing generic data layer implementation which provides standard crud functionality, error handling, connection management - the works. I'll be talking to SQL Server only.
Might want to check out Subsonic. Though I personally find it quite limited, it's certainly not an ORM, but a "query tool." It will make CRUD operations easy and straightforward, and it generates partial POCO classes for every table in your database, rather than trying to map from a database to a domain layer.
Microsoft's Entity Framework might be what you are looking for to releave you from writing "the code that talks to the database".
The best things are that it already ships with Visual Studio and - depending on your requirements - you can use most functionality out-of-the box or manually adjust it to your custom business logic via T4 templates.
You can use it for forward and reverse engeneering and being a microsoft technology it integrates well with other MS products like SQL server.
I started using it 3 months ago in my current project at work which is composed of several windows and WCF services to convert third party data into our own database scheme. From the experiences we made with it, we'll be using the EF in future project a lot more.
What would you expect this framework to do with your exceptions? If it can't connect to your database, what should it do - crash the application, show an error message (winforms or WPF or ASP)... the questions are endless.
An ORM such as those suggested elsewhere in these answers is likely to be the closest you're going to get. Expecting a third party framework to provide all your exception handling isn't realistic - how would a third party know how your application is supposed to behave?
The direct answer to your question asking for "an existing generic data layer implementation which provides standard crud functionality, error handling, connection management - the works" is simple: use ADO.NET. The answers everyone else have provided actually go beyond that functionality, but your responses suggest that you think that there's something even further beyond - something that implements your data layer for you. My suggestion is that what you're looking for probably doesn't exist.

Using HSQL for .NET development and related questions of process

My team uses a shared instance of Oracle for development using C#, NHibernate and ASP.NET, and we occasionally step on each others toes when making data or schema changes holding up everyone.
On another project I'm using Java and HSQL in 100% in-memory mode and just have Hibernate launch a script to import enough data to test with. It also creates and drops the schema. I considered using the same approach in .NET-land. With everything temporary and independent it would be impossible to step on each others toes, and we could still integrate our schema and data on the shared Oracle box.
I looked for HSQL on .NET and SharpHSQL seems to be a dead project (last release 2005).
Is there an active project equivalent to HSQL for .NET, or anything close enough to be used this way?
How have you got on using this approach in a team environment? Any issues?
How do you manage and version control data for populating the database? Is there a cross-platform solution for importing data?
With something like Sqlite, you could take the same approach in your .NET applications as with your Java applications - creating the schema and populating test data via NHibernate schema export / NHibernate population code is a good way to manage this scenario (NHibernate works fine with Sqlite). If you chose to, you could potentially standardise on Sqlite with your Java applications too.
See the HSQLDB.org web site. There is now a .NET implementation.
Edit: The implementation is for HSQLDB 1.8.0.x and is in the SVN repository. Needs to be compiled for use.
Take a look at Effort
It is basically an ADO.NET provider that executes all the data
operations on a lightweight in-process main memory database instead of
a traditional external database.
I used it in my latest project and really like it. Easy to set up.

LINQ2SQL or Entity Framework or Enterprise Library?

with LINQ2SQL, Entity Framework in the market, does it make sense to use Enterprise Library data access application block to design Data Access Layer(DAL)?
thanks.
That's like asking "Should I use a Dremel Rotary Tool or an Ingersol Rand industrial sandblasting rig?"
Can you describe what your application does and where it'll be used?
It really depends on what you are doing.
A lot of what I am writing is to existing stored procedures and other similar items. I find that SqlHelper from the Application Blocks fits my needs quite well, and haven't been compelled to change.
I have been using linq2sql and it is great. That said it can tie you with sql server (although there are third party implementations that enable linq 2 other database systems). Entity framework is rather new, but doesn't have the same restriction.
I recommend to go with either of those.

Categories