小编bak*_*nin的帖子

带有PostgreSQL的Entity-Framework 5.0

我想使用Entity-Framework 5.0作为带有PostgreSql数据库的O/R映射器.我已经阅读了许多HowTos,但我仍然被卡住了.也许我没有得到EF背后的全部想法.

我想要的是:

  • 我想自己编写代码.然后将一些属性放到属性和类中,告诉EF如何映射对象(就像我对NHibernate一样).
  • 我不想从我的模型生成数据库 - 我只想使用现有的数据库.

示例型号:

[Table("device")]
public class Device
{
    [Key]
    public int Id { get; set; }

    [StringLength(255)]
    public string Identifier { get; set; }
}

[Table("customer")]
public class Customer
{
    public Customer()
    {
        this.Devices = new List<Device>();
    }

    [Key]
    public int Id { get; set; }

    [StringLength(255)]
    public string Name { get; set; }

    // attribute required?
    public List<Device> Devices { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我做了什么:

  • 写了上面的代码
  • 创建了一个DatabaseContext类
  • 在app.config中添加了DbProviderFactories和connectionStrings
  • 使用EdmGen.exe工具生成ssdl,msl,csdl文件并将其复制到项目中(这些文件也可在bin文件夹中找到)

DatabaseContext:

public class DatabaseContext : …
Run Code Online (Sandbox Code Playgroud)

.net postgresql entity-framework

8
推荐指数
1
解决办法
4463
查看次数

JSON数据结构 - 对象的JSON - 最佳实践

我正在努力使用JSON,ASP.NET,typescript/javascript和AngularJS进行我的Web应用程序设计.

简而言之: 我需要一种最佳实践,通过JSON从服务器向客户端发送数据,使用客户端的JSON字符串创建对象.

我有一个WebServerAPI项目(ASP.NET)具有以下结构:

  • 控制器
    • DataController(REST API)
  • 模型
    • 一个
    • 类型

模型类:

public class A {
    public property int Id {get; set;}
    public property string Name {get; set;}
    public property Type Type {get; set;}
}

public class Type {
    public property int Id {get; set;}
    public property string Name {get; set;}
}
Run Code Online (Sandbox Code Playgroud)

每个模型类的id属于数据库表(主键)中的id.

DataController结构:

public class DataController : ApiController {
    // ...
    // GET api/a
    public IEnumerable<A> Get()
    {
        // fetches all As from the database
        // the facade creates instances …
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net json typescript

6
推荐指数
1
解决办法
2819
查看次数