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();
}
}
}
}
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; }
}
}
Code: Select all
var products = (new PostgresDataContext()).GetTable().ToList()
Code: Select all
Devart.Data.Linq.LinqCommandExecutionException : Error on executing DbCommand.
----> Devart.Data.PostgreSql.PgSqlException : relation "products" does not exist