我在同一条船上,我无法在 EDM 文件中添加添加实体。我已经从 Rocketsoftware 下载了最新的 .NET Toolkit 1.3。是我遗漏了什么,还是设计师仍在等待中。
请让我知道,因为这将使连接到 UniData 变得轻而易举。
谢谢。
您需要执行以下步骤在 Visual Studio 2013 中创建实体数据模型。
右键单击项目并选择添加新项目。
在右侧,选择“数据”,在左侧选择“ADO.NET 实体数据模型”。在名称字段中,输入客户。选择“添加”按钮
选择“EF Designer from database”并选择“Next”</p>
选择连接字符串并为敏感数据选择“是”
选择实体框架 5.0。注意:v2.1.1 将包含 Entity Framework 6.0 功能。
选择所有表
按完成,您将看到实体数据模型
您还可以使用 LINQ to Entity Code First 模型、Visual Studio 2013 和 U2 Toolkit for .NET v2.1.0。
有关 U2 Toolkit for .NET v2.1.0 的更多信息,请参见下文。
public class CUSTOMER
{
public int CUSTID { get; set; }
public string FNAME { get; set; }
public string LNAME { get; set; }
public virtual ICollection<CUSTOMER_ORDER> Orders { get; set; }
}
public class CUSTOMER_ORDER //Syntax : FILENAME_ASSOCIATION OR FILENAME_MULTIVALUE
{
[Column (Order =0)]
public int CUSTID { get; set; }
[Column(Order = 1)]
public string PRODID { get; set; }
[Column(Order = 2)]
public string SER_NUM { get; set; }
[Column(Order = 3)]
public int Z_MV_KEY { get; set; }
[Column(Order = 4)]
//[ForeignKey("CUSTID")]
public virtual CUSTOMER Customer { get; set; }
}
public virtual ICollection<CUSTOMER_ORDER> Orders { get; set; }
公共虚拟客户客户{获取;放; }
public class CustomerContext : DbContext
{
public CustomerContext()
{
}
public DbSet<CUSTOMER> Customers { get; set; }
public DbSet<CUSTOMER_ORDER> Orders { get; set; } //Syntax : FILENAME_ASSOCIATION OR FILENAME_MULTIVALUE
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<PluralizingEntitySetNameConvention>();
modelBuilder.Conventions.Remove<OneToOneConstraintIntroductionConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<AssociationInverseDiscoveryConvention>();
modelBuilder.Conventions.Remove<DatabaseGeneratedAttributeConvention>();
modelBuilder.Conventions.Remove<DeclaredPropertyOrderingConvention>();
modelBuilder.Conventions.Remove<RequiredNavigationPropertyAttributeConvention>();
modelBuilder.Entity<CUSTOMER>().Property(t => t.CUSTID)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Database.SetInitializer<CustomerContext>(null);
modelBuilder.Entity<CUSTOMER>()
.HasKey(pk => new { pk.CUSTID })
.ToTable("CUSTOMER");
modelBuilder.Entity<CUSTOMER_ORDER>()
.HasKey(pk => new { pk.CUSTID, pk.Z_MV_KEY })
.ToTable("CUSTOMER_ORDER");//Syntax : FILENAME_ASSOCIATION OR FILENAME_MULTIVALUE
modelBuilder.Entity<CUSTOMER_ORDER>()
.HasRequired(c => c.Customer)
.WithMany(p => p.Orders)
.HasForeignKey(c => c.CUSTID)
.WillCascadeOnDelete(false);
}
}
<add name="CustomerContext" connectionString="Database=HS.SALES;User ID=user;Password=mypass;Server=myserver;Pooling=false;ServerType=universe;PersistSecurityInfo=true;AccessMode=Native;RpcServiceType=uvcs" providerName="U2.Data.Client"/>
static void Main(string[] args)
{
try
{
Console.WriteLine("Start...");
Database.SetInitializer<CustomerContext>(null);
CustomerContext ctx = new CustomerContext();
var q = ctx.Customers.ToList();
foreach (var item in q)
{
string lCUSTID = Convert.ToString(item.CUSTID);
string lFNAME = Convert.ToString(item.FNAME); ;
string lLNAME = Convert.ToString(item.LNAME); ;
Console.Write("CUSTID:" + lCUSTID);
Console.Write(" FNAME:" + lFNAME);
Console.Write(" LNAME:" + lLNAME);
foreach (var item2 in item.Orders)
{
string lCUSTID2 = Convert.ToString(item2.CUSTID);
string lPRODID = Convert.ToString(item2.PRODID); ;
string lSER_NUM = Convert.ToString(item2.SER_NUM);
string lZ_MV_KEY = Convert.ToString(item2.Z_MV_KEY);
Console.Write("\t"+"CUSTID:" + lCUSTID2);
Console.Write("\t" + " PRODID:" + lPRODID);
Console.Write("\t" + " SER_NUM:" + lSER_NUM);
Console.Write("\t" + " Z_MV_KEY:" + lZ_MV_KEY);
}
Console.WriteLine();
}
Console.WriteLine("End...");
Console.Read();
}
catch (Exception e)
{
string lErr = e.Message;
if (e.InnerException != null)
{
lErr += e.InnerException.Message;
Console.WriteLine(lErr);
}
}
}