This is a migrated thread and some comments may be shown as answers.

code only mapping to make table name a variable

3 Answers 40 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chom
Top achievements
Rank 1
Chom asked on 11 Mar 2014, 08:55 PM
Hello,

I am creating my schema using code only and I need to create several tables using the same table schema only with a different name. I need to add a variable string for MappingConfiguration ToTable("mystring") method. In other words I need to have ToTable(MyVariable). I am not sure how to
achieve this. The problem is when I call UpdateSchema(), the variable logic is somehow lost when creating the table mapping. Below is an idea of what I am doing.

  protected override Telerik.OpenAccess.Metadata.MetadataContainer CreateModel()
{
Telerik.OpenAccess.Metadata.MetadataContainer model = base.CreateModel();
model.DefaultMapping.NullForeignKey = true;
return model;
}

protected override IList<MappingConfiguration> PrepareMapping()
{
List<MappingConfiguration> config = new List<MappingConfiguration>();

MappingConfiguration<Template> template = new MappingConfiguration<Template>();
template.MapType(x => new
{
Id = x.Id,
Name = x.Name,
Value = x.Value
}).ToTable(MyVariable);
template.HasProperty(p => p.Id).IsIdentity();
template.HasProperty(p => p.Name).IsNotNullable().IsUnicode().HasLength(100);
template.HasProperty(p => p.Value).IsNullable().IsUnicode().HasLength(100);

config.Add(template);

return config;
}
}

3 Answers, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 13 Mar 2014, 09:02 AM
Hello Gavin,

In order for us to understand your scenario and assist you in the best possible way, could you please provide us some more information:
1) How do you want to pass the variable to the PrepareMapping() method?
2) Do you want to use the variable only once to update the database schema?
3) Do you want to change the variable and the mapping at runtime?

I also suggest you to take a look at the Artificial Types API provided by Telerik Data Access which gives you the opportunity to your persistent model during the runtime.

I am looking forward to hearing from you.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Chom
Top achievements
Rank 1
answered on 19 Mar 2014, 11:07 AM
Hi Boris,
I was able to create the tables using script and executenonquery

​ using (DataLogFluentContext db = new DataLogFluentContext(ConnectionType))
{
db.ExecuteNonQuery("CREATE TABLE " + tables etc);
                db.SaveChanges();
}

but I would like to have the option to select between different databases to create tables. What is the best way to send a small demo app?

Thanks

Gavin
0
Boris Georgiev
Telerik team
answered on 19 Mar 2014, 02:20 PM
Hello Gavin,

I am glad to see that you have found a solution. 

The forum thread is changed into a Product Feedback ticket, so you are now allowed to add attachments.

I am looking forward to hearing from you.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Development (API, general questions)
Asked by
Chom
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Chom
Top achievements
Rank 1
Share this question
or