首页 \ 问答 \ 使用流畅映射的Entity Framework中的一对多(One to many in Entity Framework using fluent mapping)

使用流畅映射的Entity Framework中的一对多(One to many in Entity Framework using fluent mapping)

我试图通过使用流畅的api做一对多的地图。 这是我的课程

    public class Product : EntityBase
{
    public Product()
    {
        this.ProductArticles = new List<ProductArticle>();
    }

    [Key]
    public int ProductId { get; set; }
    public string Description { get; set; }
    public string ReportText1 { get; set; }
    public string ReportText2 { get; set; }
    public bool Standard { get; set; }
    public int ProductGroupId { get; set; }
    public decimal? Surcharge1 { get; set; }
    public decimal? Surcharge2 { get; set; }
    public decimal? Surcharge3 { get; set; }
    public decimal? Surcharge4 { get; set; }
    public decimal PriceIn { get; set; }
    public decimal PriceOut { get; set; }
    public decimal PriceArtisanIn { get; set; }
    public decimal PriceArtisanOut { get; set; }
    public decimal PriceTotalIn { get; set; }
    public decimal PriceTotalOut { get; set; }
    public decimal PriceTotalOutVat { get; set; }
    public decimal PriceAdjustment { get; set; }
    public bool Calculate { get; set; }
    public string Notes { get; set; }
    [ForeignKey("ProductGroupId")]
    public virtual ProductGroup ProductGroup { get; set; }

    public virtual ICollection<ProductArticle> ProductArticles { get; set; }
}

public class ProductArticle : EntityBase
{
    [Key]
    public int ProductArticleId { get; set; }
    public int ProductId { get; set; }
    public int ArticleId { get; set; }
    public decimal Qty { get; set; }
    public decimal PriceIn { get; set; }
    public bool Primary { get; set; }
    public virtual Product Product { get; set; }
    public virtual Article Article { get; set; }
}

现在我想从单个产品包括所有ProductArticles

这是我的映射

    public class ProductMap : EntityTypeConfiguration<Product>
{
    public ProductMap()
    {
        // Primary Key
        this.HasKey(p => p.ProductId);

        // Table & Column Mappings
        this.ToTable("Product");
        this.HasMany(p => p.ProductArticles)
            .WithOptional()
            .Map(p => p.MapKey("ProductId").ToTable("ProductArticle"));
    }

但它不起作用..请帮忙:)


Im trying to do a one-to-many map by using fluent api. This is my classes

    public class Product : EntityBase
{
    public Product()
    {
        this.ProductArticles = new List<ProductArticle>();
    }

    [Key]
    public int ProductId { get; set; }
    public string Description { get; set; }
    public string ReportText1 { get; set; }
    public string ReportText2 { get; set; }
    public bool Standard { get; set; }
    public int ProductGroupId { get; set; }
    public decimal? Surcharge1 { get; set; }
    public decimal? Surcharge2 { get; set; }
    public decimal? Surcharge3 { get; set; }
    public decimal? Surcharge4 { get; set; }
    public decimal PriceIn { get; set; }
    public decimal PriceOut { get; set; }
    public decimal PriceArtisanIn { get; set; }
    public decimal PriceArtisanOut { get; set; }
    public decimal PriceTotalIn { get; set; }
    public decimal PriceTotalOut { get; set; }
    public decimal PriceTotalOutVat { get; set; }
    public decimal PriceAdjustment { get; set; }
    public bool Calculate { get; set; }
    public string Notes { get; set; }
    [ForeignKey("ProductGroupId")]
    public virtual ProductGroup ProductGroup { get; set; }

    public virtual ICollection<ProductArticle> ProductArticles { get; set; }
}

public class ProductArticle : EntityBase
{
    [Key]
    public int ProductArticleId { get; set; }
    public int ProductId { get; set; }
    public int ArticleId { get; set; }
    public decimal Qty { get; set; }
    public decimal PriceIn { get; set; }
    public bool Primary { get; set; }
    public virtual Product Product { get; set; }
    public virtual Article Article { get; set; }
}

Now i want from single Product include all ProductArticles

This is my mapping

    public class ProductMap : EntityTypeConfiguration<Product>
{
    public ProductMap()
    {
        // Primary Key
        this.HasKey(p => p.ProductId);

        // Table & Column Mappings
        this.ToTable("Product");
        this.HasMany(p => p.ProductArticles)
            .WithOptional()
            .Map(p => p.MapKey("ProductId").ToTable("ProductArticle"));
    }

But it doesnt work.. Please help :)


原文:https://stackoverflow.com/questions/18784294
更新时间:2022-06-03 06:06

最满意答案

还没有采用这个来解决我现在的PC /蓝牙通信问题(目前使用32feet和C#)但是我确实遇到了一个用于C ++的本地Microsoft库: https ://msdn.microsoft.com/en-us/library/ 窗户/桌面/ aa362932%28V = vs.85%29.aspx

正如我所说,我自己没有尝试过,所以不能保证,但它可能值得一看?


Not yet resorted to this for my own current PC/Bluetooth comms woes (currently working with 32feet and C#) however I did come across a native Microsoft library for C++: https://msdn.microsoft.com/en-us/library/windows/desktop/aa362932%28v=vs.85%29.aspx

As I say I've not tried it myself so can't vouch for it but it may be worth a look?

相关问答

更多
  • 为可能面临类似情况的其他人发布此答案。 基本上要创建一个蓝牙端点,你需要一个有效的适配器蓝牙MAC地址。 要获取本地机器的本地蓝牙MAC地址,请使用 BluetoothRadio.PrimaryRadio.LocalAddress 所以上面的代码将需要更改为 public static BluetoothAddress GetBTMacAddress() { BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio; ...
  • 例如,“E:23.txt”不是文件的有效路径。 永远记住你的斜线,它们非常重要! 因此,您可以从以下位置更改它: e32socket.bt_obex_send_file(address,channel,u"E:23.txt") 至 e32socket.bt_obex_send_file(address,channel,u"E:\\23.txt") 另外,我对bt_obex_receive不太熟悉,但你也想修复那条路径。 此外,您正在导入appuifw模块而不使用它。 除非您计划添加使用它的代码,否则导入 ...
  • 应该发生异常:在20秒之后,然后执行下一个IO操作。 你在等那么久吗? 或者你的阅读电话是否归零? 请参阅https://32feet.codeplex.com/wikipage?title=Connected%20Property上的 #2 在我使用蓝牙进行的测试中,一台设备似乎需要大约20秒才能意识到其他设备已经消失 - 尽管这可能是可配置的。 这在蓝牙中称为“链路监控超时”。 因此,您必须等待很长时间才能让系统知道连接丢失,然后您将在下一次IO操作时发现如果您在没有接收到数据时开始读取,它将阻止直到连 ...
  • 解决方案很简单。 我只是忘了定期发送一份LifeSignMsg stream.Write(new byte[] { 0x02, 0x23, 0x00, 0x00, 0x03 }, 0, 5); The solution was simple. I just forgot to send a periodic LifeSignMsg like stream.Write(new byte[] { 0x02, 0x23, 0x00, 0x00, 0x03 }, 0, 5);
  • 还没有采用这个来解决我现在的PC /蓝牙通信问题(目前使用32feet和C#)但是我确实遇到了一个用于C ++的本地Microsoft库: https ://msdn.microsoft.com/en-us/library/ 窗户/桌面/ aa362932%28V = vs.85%29.aspx 正如我所说,我自己没有尝试过,所以不能保证,但它可能值得一看? Not yet resorted to this for my own current PC/Bluetooth comms woes (curren ...
  • 因此,对于SPP服务(RFCOMM),您可以使用您可能已经知道的UUID“00001101-0000-1000-8000-00805F9B34FB”,我正在使用它,它在115.2K波特率下工作正常。 然后在一个单独的线程中管理连接,如果你去Android的开发者门户 ,他们有一个解释的例子和协议的良好信息。 使用蓝牙API,Android应用程序可以执行以下操作: - 扫描其他蓝牙设备 - 为配对的蓝牙设备查询本地蓝牙适配器 - 建立RFCOMM通道 - 通过服务发现连接到其他设备 - 从其他设备传输数据 ...
  • 也可能只是在Windows中没有打开蓝牙。 我使用的是.NET InTheHand库,并且只收到此消息,因为在Windows中关闭了BlueTooth,并通过激活BlueTooth解决了这个问题。 I just solved this. I think the problem was an old reference in my project to the NETCF version of the DLL from when I was trying to brute-force a solution, ...
  • 该问题与连接配对如何存储在注册表中无关。 事实证明,当你打开一个串口时,你需要让它稳定下来才能做任何事情。 理想情况下,只有在稳定后才会从“IsOpen”属性中获得真实,但是如果没有,则只需添加延迟... this.serialPort.Open(); // Delay to ensure that the serial port is in a stable state Thread.Sleep(StabilisationDelay ...
  • 看起来在某些时候没有用户交互的配对是可能的,从这个判断: 在进行程序化配对时,如何避免或取消Android的蓝牙配对通知? 但是,看起来仍然出现了要求PIN的通知消息,他们无法解决这个问题。 OP所描述的基本方法似乎一直在研究2.3但我猜(并且希望,因为它充满了巨大的安全风险)它已不再存在了。 Looks like pairing without user interaction was possible at some point, judging by this: How can I avoid or ...
  • 您只需列出文件夹/文件夹中的文件,然后单独上传/下载。 OBEX中没有其他功能。 You just have to list the files in the folder/folders and up-/download each individually. There are no other features in OBEX for this.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)