0

I'm a newbie with devexpress and i have a few difficulty.

I have create a project ".net empty c#" with visual studio. I would like connect at my database "mysql" with "devexpress xpo".
I create a "dxperience orm data model wizard" to connect at my database. At the end i have a "connectionHelper.cs"(with few method static) and a class with the name of my table.

But I not understand , how connect,read,write,... at the database with the connectionHelper? I read the documentation of devexpress but I not have the same result.

thank you in advance

The class connection helper:

using DevExpress.Xpo;
using DevExpress.Data.Filtering;
namespace ProduWebEmpty.produweb
{
    public static class ConnectionHelper
    {
        public const string ConnectionString = @"XpoProvider=MySql;server=localhost;user id=root; password=; database=web;persist security info=true;CharSet=utf8;";
        public static void Connect(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption)
        {
            XpoDefault.DataLayer = XpoDefault.GetDataLayer(ConnectionString, autoCreateOption);
            XpoDefault.Session = null;
        }
        public static DevExpress.Xpo.DB.IDataStore GetConnectionProvider(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption)
        {
            return XpoDefault.GetConnectionProvider(ConnectionString, autoCreateOption);
        }
        public static DevExpress.Xpo.DB.IDataStore GetConnectionProvider(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption, out IDisposable[] objectsToDisposeOnDisconnect)
        {
            return XpoDefault.GetConnectionProvider(ConnectionString, autoCreateOption, out objectsToDisposeOnDisconnect);
        }
        public static IDataLayer GetDataLayer(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption)
        {
            return XpoDefault.GetDataLayer(ConnectionString, autoCreateOption);
        }
    }
}

The class authentification.cs (authentification is the name of my table into my database)

using DevExpress.Xpo;
using DevExpress.Data.Filtering;
namespace ProduWebEmpty.produweb
{
    public partial class authentification
    {
        public authentification(Session session) : base(session) { }
        public authentification() : base(Session.DefaultSession) { }
        public override void AfterConstruction() { base.AfterConstruction(); }
    }
}

The class authentification.designer.cs:

using DevExpress.Xpo;
using DevExpress.Data.Filtering;
namespace ProduWebEmpty.produweb
{

    public partial class authentification : XPLiteObject
    {
        int fId;
        [Key(true)]
        public int Id
        {
            get { return fId; }
            set { SetPropertyValue<int>("Id", ref fId, value); }
        }
        string fPseudo;
        [Size(255)]
        public string Pseudo
        {
            get { return fPseudo; }
            set { SetPropertyValue<string>("Pseudo", ref fPseudo, value); }
        }
        string fMotDePasse;
        [Size(255)]
        public string MotDePasse
        {
            get { return fMotDePasse; }
            set { SetPropertyValue<string>("MotDePasse", ref fMotDePasse, value); }
        }
        string fEmail;
        [Size(255)]
        public string Email
        {
            get { return fEmail; }
            set { SetPropertyValue<string>("Email", ref fEmail, value); }
        }
    }
}
Dennis Garavsky
  • 538
  • 3
  • 18
Zoners
  • 53
  • 1
  • 4
  • 12

2 Answers2

1

to connect to your Datebase:

IDataLayer db_layer = XpoDefault.GetDataLayer(new SqlConnection(@sqlCon_str),
    DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema);
    Session session =new Session(db_layer);

mypersistent record =new mypersistent(session){
property1="string property",
property2=123456
};
record.Save(); // save new record(line) to Database With Unique Oid

to read:

//if you know the Unique_Oid so:
mypersistent record=session.FindObject<mypersistent>(CriteriaOperator.Parse("Oid = ?",Unique_Oid );

Console.WriteLine(string.Format("property1 = {0} , property2={1}",record.property1,record.property2));

else you can read a Collection:

XpCursor collection=new XpCursor(session,typeof(mypersistent),CriteriaOperator.Parse("property1 = '?'","string property");

foreach(mypersistent p in collection) { /* .... */ }

to delete:

//after getting record from database (above) 

record.Delete();

to update

//Update

record.property1="Hello";
record.Save();
0

You can get started with the instructions listed in the How to use XPO in an ASP.NET (Web) application KB Article.

The examples available in the "Examples" section illustrate main scenarios in action.

Mikhail
  • 9,186
  • 4
  • 33
  • 49
  • 1
    The ConnectionHelper class just provides you with helpful methods to configure your database connection. For instance, if you are using an ASP.NET application, put the ConnectionHelper.Connect call into the Application_Start method within the Global.asax.cs file. Refer to the help article Mike suggested above for more details. Please use the official DevExpress support channel: www.devexpress.com/sc (it is FREE during 30 day evaluation period) if you require more assistance on this task. – Dennis Garavsky Oct 04 '12 at 08:22