Print Page | Close Window

Constrains in DataBase.

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3530
Printed Date: 07-Apr-2025 at 9:04pm


Topic: Constrains in DataBase.
Posted By: rbautistaole
Subject: Constrains in DataBase.
Date Posted: 10-Jul-2012 at 7:00pm
Hi.
In DevExpress.XPO i can mark a property with a attribute as

[Indexed("CampoB", Unique = true)]

public int CampoA {
 
to generate a composed index (campoA, campoB) on the database either unique or not.
Do Devforce has some equivalent?
thanks.



Replies:
Posted By: sbelini
Date Posted: 12-Jul-2012 at 10:02am
Hi,
 
If using Code First, you can create the index in the DbContext: ( http://stackoverflow.com/questions/4995642/add-index-with-entity-framework-code-first-ctp5 - - http://stackoverflow.com/questions/4413084/unique-constraint-in-entity-framework-code-first )
 
public class Initializer : IDatabaseInitializer<MyDbContext> {
  public void InitializeDatabase(MyDbContext context) {
    ...
    context.Database.ExecuteSqlCommand("CREATE INDEX...");
  }
}
 
In Model First/Database First, unfortunatelly there's no equivalent for the "Indexed" attribute in DevForce. (Actually EF does not support it)
Regards,
   Silvio.



Print Page | Close Window