DNN MVC Module with Sql Hierarchy Id - petapoco

Quick question here. Has anyone used the sql hierarchy id type in their dnn mvc module with peta poco? Do you need to write a custom query to cast the data type? Do you need to add sql server types to the project?
Thanks!

Out of the box, PetaPoco doesn't support this type. However, PetaPoco does support some flexible mapping points.
Off the top of my head, you can declare your own mapping type. See Interface & Docs & Registration
Another method is to hook the type mapping using the fluent configuration method. See example & Docs

Related

Can the ASP.NET Entity Framework automatically generate data annotations?

My team is writing a large scale business website in ASP.NET MVC 4 using the database-first approach. Does anyone know if it's possible to have data annotations automatically generated based on the database schema? It seems redundant to have to manually write the "buddy" metadata classes containing the data annotations when the framework should be aware of a database column's properties and make these part of the POCO classes it generates. Any suggestions would be greatly appreciated!
Take a look at LINQ to SQL.
You can use it to create a .dbml file in a graphical editor by dragging the tables from the server explorer.
Here's the MSDN How to: Create LINQ to SQL Classes in a Web Project
1) The framework does a good job of extrapolating data annotation based on table structure, but they won't be perfect.
2) Sadly, when you reach a point when you want to customize more than the framework, you are stuck with Buddy classes. They're a bit tedious but so far the best method I've found for customizing data annotation.
3) All too often, I find myself gravitating toward custom classes and away from generated POCO's. The reason is usually the differences between storing and displaying. In entry screens
I will often break up phone #'s into 3 textboxes.
Lookups for foreign keys require select lists (often added to model).
Often I'll pass other values that may be relevant to my View functionality but not specific to the storage table (display fields, navigation / bread crumbs)
Use the Database First approach with the Entity Framework.
You can generate the entity model from an existing database using the entity data model wizard.
See http://msdn.microsoft.com/en-us/data/jj206878
#Kerezo covers pretty much exactly what you want to do here: Add Data Annotation To Entity Framework(Or Linq to SQL) generated class
It is not possible to auto generate the data annotations automatically.

NHibernate Database-First

I'm putting a front-end together for one of our databases and would like to use NHibernate for it.
Can anyone point out any resources for getting started with Database-first approach? Most tutorials I've seen are for Code/Entity First.
ASP.NET MVC 3 will be my environment, if it matters.
Thanks.
It is all about configuring with NHibernate. As long as Nhibernate is concern, it will not create a database if that is not exists. So you have to configure Nhibernate with the connection string of your existing database in hibernate.cfg.xml(You can also use loquacious api)
There are lots of configuration possibility in NHibernate; Example includes ConfORM, FluentNhibernate, Configuring With Code, XML.
For existing database going with xml is often easy. If you choose xml, you can use tools like myGeneration to generate mappings for you.
As long as you map your object correctly with the existing database nibernate will not complain whether you create your database first or code first. So any intorductory example/application/resource that uses nhibernate as an orm mapper should serve as getting started for you.
Still there are some techniques you can follow to do database first modeling. Here is a link that may help(code example) Effective Techniques for Database-Driven Modeling
Here is the Screen Cast Explaining the techniques
please take a look at this: http://www.devart.com/entitydeveloper/nhibernate-designer.html it is not a freeware.
There is another open source tool which was referred in another question long time back. here is the link: http://www.mygenerationsoftware.com/phpBB2/viewtopic.php?t=1505
btw are you planning to use fluent nhibenrate or just nhibernate?
On a side note: Entity Framework supports a database-first approach with an integrated designer for Visual Studio. This designer produces an XML file (EDMX) that describes the required mappings.
Note: I am not marketing any of these products.

A single place in NHibernate and Sharp Architecture to specify field length for database and validation

I'm building a new system with NHibernate, using S#arp Architecture. I'm new to S#arp, but experienced with NHibernate. One feature I was really hoping to find was a nice way to specify in one place text field lengths that would be carried through to every layer that needs to know the length.
In other words, I use Fluent mapping to specify that the Name field of a Whatsis object is 50 characters. (I turned off automapping because I was still writing mapping overrides for most, if not all classes. I decided just to write the full mapping myself with ClassMap. I want enough detail in the mapping to generate the complete DB schema from it.) Then when I generate the database schema using hbm2ddl, I get a 50-character field length. That's great. But I also want the MVC validators to enforce it automatically. And I'm so greedy I even want the proxy object the NHibernate generates for Whatsis to know about that length in its setter, so if in code I should assign a too-long value, I'll get an exception.
Do I have any hope of achieving this without really overcomplicating my project? This is my first time using Fluent mapping. I thought this was a feature of Fluent, but it looks like it doesn't work that way after all.
You need to use NHibernate Validator as that is the only validator framework that NHibernate hbm2ddl currently supports. Unfortunately it doesn't look like anyone has wired together NHibernate Validator and MVC3 validations. Here is someone else having problems with it:
MVC 3, NHIbernate Validators & Message Interpolator
It should be possible as I've used xVal (predecessor to MVC3 validators) in the past with NHibernate Validator attributes for client-side validation, server-side validation, and schema generation. Someone just needs to invest some TLC to get NHibernate Validator playing nicely with MVC3 validators.

Using NHibernate for DotNetNuke Modules?

I'm thinking of adopting a more Domain-Driven-Design approach to DotNetNuke module development and would like to consider using NHibernate as an OR/M layer.
Does anyone have experience using NHibernate with DotNetNuke? I've used SubSonic and EntitySpaces, but not NH.
UPDATE
Sorry, I should have been more clear. Is NHibernate capable of running in Medium Trust and able to run in the context of the DotNetNuke "objectqualifier" ? The DNN object qualifier is essentially a prefix that can be applied to all database table names. So on my DNN install I might have a table named "Products", but on someone else's the same table might be named "dnn_Products" where the "dnn" is the "objectqualifier". So essentially NHibernate would need to read the objectqualifier from the web.config at runtime and apply it.
NHibernate can be used with essentially any table name. When you define the table mapping in your mapping xml you need to simply define the table name as dnn_Products. As long as that is the actual name of the table then it will work. NHibernate is capable of running in Medium Trust, the trick is getting the NHibernate dll's into your DNN install. You can add them in an Assembly Component from what I understand but I have never had the need to validate that personally.
You can see this example.
The article is not for the same topic you are looking but it will give you good idea about it.

Entity Framework: Generating database from classes

Is it possible to create the database from the classes with entity framework 4.0? I found many tutorials on how to do it the other way round. But since we have already implemented and tested all classes of the domain we'd like to avoid changing them to much.
If I used the wrong keywords in Google I'd appreciate you could post a link.
Cheers,
CA
Yes, it is possible. The approach is known as "model-first".
You define your entities with designer then call for "Generate database script" or something. Run this SQL against a database and it will create tables and relationships.
This is quite easy to do with Fluent NHibernate using Auto Mapping. You could also use Fluent Mapping if you want more control over how your entities are mapped, but this will require writing mapping classes. It shouldn't affect your existing classes though.
While looking up an other question on Stackoverflow I found an the solution for my problem:
Entity Framework 4 / POCO - Where to start?