我在同一条船上,我无法在EDM文件中添加添加实体。我从Rocketsoftware下载了最新的.NET Toolkit 1.3。我错过了什么,或者设计师还在等待。
请告诉我,因为这样可以轻松连接到UniData。
感谢。
答案 0 :(得分:0)
您需要执行以下步骤以在Visual Studio 2013中创建实体数据模型。
右键单击Project并选择Add New Item。
在右侧,选择“数据”,在左侧选择“ADO.NET实体数据模型”。在“名称”字段中,输入“客户”。选择“添加”按钮
从数据库中选择“EF Designer”并选择“下一步”
选择连接字符串,并为敏感数据选择“是”
选择Entity Framework 5.0。 注意:v2.1.1将包含Entity Framework 6.0功能。
选择所有表格
按“完成”,您将看到“实体数据模型”
答案 1 :(得分:0)
您还可以使用LINQ to Entity Code First Model,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 virtual CUSTOMER Customer {get;组; }
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);
}
}
}