question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fluent ....HasTableName(..) works only first time (version 1.0.7.4)

See original GitHub issue

Seems like changing mapping TableName with fluent mapping works only once per process instance.

Example: I have a set of tables with same data models.

        // Data model class (for different tables):
        public class SomeModel
        {
            [Column("id")]
            public int Id { get; set; }
            [Column("field")]
            public string Field { get; set; }
        }

        // Testing mapping same class with different tables (in different instances of DbConnection!)
        public void Test()
        {
            var confName = "Test";

            // map to table1
            using (var db = new LinqToDB.Data.DataConnection(confName))
            {
                db.MappingSchema.GetFluentMappingBuilder().Entity<ModelBase>().HasTableName("table1");
                var q = db.GetTable<ModelBase>(); // = sql=... from "table1"...
                var t = q.ToArray();  // <--- mapped to "table1" 
            }
            // map to table2
            using (var db = new LinqToDB.Data.DataConnection(confName))
            {
                db.MappingSchema.GetFluentMappingBuilder().Entity<ModelBase>().HasTableName("table2");
                var q = db.GetTable<ModelBase>(); // = sql=... from "table1"... !!
                var t = q.ToArray();  // <--- still mapped to "table1", not "table2"  !!!
            }
        }

I am using linq2db version 1.0.7.4 Maybe I’ve missed something?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
sdanylivcommented, Oct 28, 2016

Why you do not use db.GetTable< ModelBase >().TableName(‘table1’).Select… ?

0reactions
springjazzycommented, Mar 13, 2018

Awesome. Thanks in advance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

linq2db 5.0.0-preview.1
LINQ to DB is a data access technology that provides a run-time infrastructure for managing relational data as objects.
Read more >
Fluent API - Configuring and Mapping Properties and Types
In this article. Model-Wide Settings; Property Mapping; Type Mapping; Model Used in Samples. When working with Entity Framework Code First the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found