Nhibernate, how to make unique string column - string

I have example 'object' with Id, FkAnotherObject, and string. Which attribute I have to use to have ony unique strings in table. Is there any option to do this?

unique="true" should do the trick :-)
Alternatively, unique-key allows you to create multi-column unique constraints.

Related

Unique Constraint in Couchdb

Is there any way to apply unique constraint in couchdb?
Suppose I have a document which have some fields like email, emp_id, phone_number that needs to be unique throughout the document. I could not find any way. Anyone knows how to achieve this?
Any answer/suggestion would be appreciated.
after a lot of searching, I found that If you want to add a unique constraint to only one parameter you can set it as id. But If there are multiple parameter that needs to be unique, then this is not possible in couchdb
The only unique constraint in CouchDB is on the document ID. If you can put the unique components of your data in the document ID, then you have a uniqueness constraint.

SharePoint unique values from lookup

I have a list with a lookup column that is getting "Created" dates from another list, but I only want the unique date values. Is there a way to get this data or to create a calculated column with unique values?
A lookup field actually links to a single item, the display value is more a "human readable" value for the link to the items ID value.
You may also get some mileage from a normal text or even date field and using jQuery and SPServices on the edit and new forms in order to provide changes to the form for the user. This avoids doing a code level customisation for the site that a Custom Field would require.
Not out of the box I dont think. My best bet is to create a Custom Field type that extends lookup with the functionality you are after.

Full text index and set a column as an attribute in sphinx?

I am trying to full text search a column, but also be able to group by it. Does that mean it needs to be attribute? I want to still be able to search on the column though.
Use sql_field_string to make a column both a full-text field, and an attribute.
http://sphinxsearch.com/docs/current.html#conf-sql-field-string
Then you can query it, and sort/group by it.
Yes, you need attribute to use group by in Sphinx.
For example you could use crc32(text) of your text column. Like:
sql_query = select text, crc32(text) as text_crc from mytable
sql_attr_uint = text_crc
So, text will be used for full-text search and text_crc for group by.

Simple way to use Foreign Key values for sorting?

Disclaimer: I jumped to C# 2008 recently and SubSonic 3 (3.0.0.4) at the same time. I haven't used Linq for much of anything in the past.
Is there an easy way to use the foreign key display value for sorting, rather than the FK Id (which is numeric)?
I've added a new Find method in my ActiveRecord.tt to help with sorting based on a string field name but after doing some testing I realized that even though its working as it should be, I am not handling foreign key fields at all (they are just sorting by their value).
Even if I need to change how I am accessing the data it is early enough in the project to do that. Just looking for suggestions.
LINQ is your friend in this situation, you just need to join your two objects and then sort by the property from your foreign object:
var primaryObjectsSorted =
from primaryObjects in PrimaryObject.All()
join foreignObjects in ForeignObject.All()
on primaryObjects.ForeignId equals foreignObjects.Id
orderby foreignObjects.PropertyYouWantToSortOn
select primaryObjects;
So you have table A which has id of table B as a foreign key and you want to sort table A by the DisplayName column of table B rather than the id of table B?
The only way to achive this is by a join.
SELECT tableA.* FROM tableA INNLER JOIN tableB ORDER BY tableB.DisplayName
In SubSonic2 you can do that, and still be able to update your records if you use the DB.Select(...).ExecuteCollection() method.
I think this should be possible with subsonic3, too.
Howevery, if you don't use the foreign key and the display name is unique, you should just use this value as your foreign key.

SubSonic CreatedBy

I have a CreatedBy column in a table which datatype is a int. SubSonic crashes on this because apperently it uses CreatedBy, CreatedOn, ModifiedBy and ModifiedOn. The By columns need to be strings.
Is there a way to let SubSonic know that it has to ignore these columns?
No, you probably are going to have to rename the column to CreateByUser or something.
You can also change it to a nvarchar(50) and create a column ModifiedBy nvarchar(50) and have it work just fine too.
Yes... this is totally doable. First of all show us the code that makes it crash. I probably know what it is. You are probably trying to do something like this
MyRecord.Save();
Where as you need to do pass in the id of the person that is creating the record aka.
MyRecord.Save(55);
SubSonic knows what datatype your columns are so you don't need to tell it what datatype it is. Also if you look there are overloads of the Save method namely Save(int id), Save(string id), and Save(Guid id). So as long as you use an int,string or guid for your CreateBy column you are good to go, you just need to remember to pass in the ID as SubSonic expects it if you use those columns.

Resources