Is there any workround for manual setup linqconnect?

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
oblin
Posts: 1
Joined: Mon 27 Sep 2010 17:29

Is there any workround for manual setup linqconnect?

Post by oblin » Mon 27 Sep 2010 17:52

I had problem while manual setup linqconnect for postgresql.
Here is the code:

Code: Select all

using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace Services
{
    // You must assign this Provider attribute, otherwise it will cause an unrelative error message: Devart.Data.Linq.Provider.DataProvider is abstract class
    [ProviderAttribute(typeof(Devart.Data.PostgreSql.Linq.Provider.PgSqlDataProvider))]
    public class PostgresDataContext : Devart.Data.Linq.DataContext
    {
        public PostgresDataContext() : base("Server=localhost; User Id=postgres; Password=123456; Database=TestDB; Port=5432") { }

        public Devart.Data.Linq.Table Products
        {
            get
            {
                return this.GetTable();
            }
        }
    }
}
Where Product had been defined as:

Code: Select all

using System.Linq;
using System.Data.Linq;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq.Mapping;

namespace SportsStore.Domain.Entities
{
    [Table(Name="Products")]
    public class Product
    {
        [Column(IsPrimaryKey=true, IsDbGenerated=true,AutoSync=AutoSync.OnInsert)]
        public int ProductID { get; set; }

        [Column]
        public string Description { get; set; }

        [Column]
        public decimal Price { get; set; }
  }
}
While execution:

Code: Select all

var products = (new PostgresDataContext()).GetTable().ToList()
it always show up:

Code: Select all

Devart.Data.Linq.LinqCommandExecutionException : Error on executing DbCommand.
  ----> Devart.Data.PostgreSql.PgSqlException : relation "products" does not exist
newbie here, google thousands times, can't find anything to solve out, please help.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Tue 28 Sep 2010 13:22

Apparently, the problem is that the table name is capitalized whereas you are passing it without quotes, hence PostgreSQL turns it to lower case. Please try using the following attribute for the Product class:

Code: Select all

[Table(Name = "\"Products\"")]
Here the table name is quoted, so PostgreSQL will search for "Products" instead of "products".

Please tell us if this helps.

Post Reply