Ria +协会-如何进行这项工作? [英] Ria + Associations - How to make this work?

查看:78
本文介绍了Ria +协会-如何进行这项工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经为这个问题苦苦挣扎了好几天,无法使其正常工作!通过阅读论坛中的帖子,我可以理解这里的一些人已经在LS中做到了这一点.

我使用ria可扩展,并且总是很好用.但是,我需要为两个实体建模并以一对多的方式关联它们.我以前没有做过.

我读过这样的帖子:

http://social. msdn.microsoft.com/Forums/zh-CN/lightswitchgeneral/thread/e7c5273b-ce22-4b20-9d9e-f8be123f938f

包含应以ria表示的关联方式.

但是,我将发布我的代码,以便有人可以帮助我找到我做错的事情.

这些是我在ria中的实体:

Transaccion公共类

    {

        [键]

        public int ID {get;放; }

        (这里有一些属性...)

        [包含]

        [Association("Transaccion_Operaciones","ID","TransaccionID",IsForeignKey = false)]

       公共ICollection< Operacion>歌剧{放; }

    }

 

   公共课Operapion

    {

        [键]

        public int ID {get;放; }

        public int TransaccionID {get;放; }

        (这里有一些属性...)

        [包含]

        [Association("Transaccion_Operaciones","TransaccionID","ID",IsForeignKey = true)]

       公共Transaccion Transaccion {get;放; }

    }

在查询中,我从模型(外部db)中的实体读取数据,并使用列表填充这两个实体.发行

解决方案

我仍然无法解决我的问题.我认为阅读过这篇文章的人已经检查了实体类在c#中的编码方式,然后找到正确的方法.

因此,我决定发布简化的查询版本,以构建并返回父子实体,以查看是否可以发现任何可能的错误原因.我的意思是孩子*不能*进入LS中的客户端屏幕的原因.

这是我用来编写查询的代码:

[Query(IsDefault = true)]

       公共IQueryable< Transaccion> GetTransaccion()

        {

            List< Transaccion> list = new List< Transaccion>();

           返回list.AsQueryable();

        }

 

[Query(IsDefault = true)]

       公共IQueryable< Operacion> GetOperacion()

        {

            List< Operacion> list = new List< Operacion>();

           返回list.AsQueryable();

        }

 

       公共IQueryable< Transaccion> GetTransaccionByFilter(int?cia,字符串referencia,字符串来源)

        {

 

            //使用参数我构建过滤器"字符串...

 

            var query = from Context.TransaccionesFinancieras中的t.

                       包括("TransaccionesFinancieras_Operaciones").

                       哪里(过滤器)

                       选择t;

 

           简短的我= 0;

            Transaccion transaccion;

           列表< Transaccion> transaccion_List =新列表< Transaccion>();

 

 

            foreach(查询中的TransaccionesFinanciera t)

            {

                transaccion =新的Transaccion()

                {

                    ID =我,

                    //在这里填充父"实体属性,并将Operaciones实例化为列表

                    Operaciones = new List< Operacion>()

 

                };

 

               操作;

               简短的OperacionID = 0;

 

                foreach(t.TransaccionesFinancieras_Operaciones中的TransaccionesFinancieras_Operacione o)

                {

                   操作=新的Operacion()

                    {

                        ID =操作符ID,

                        TransaccionID = transaccion.ID,

                        //更多属性在此处获得其值                   

                    };

                    //这是父"实体的属性

                    operaccion.Transaccion = transaccion; 

 

                    //然后将孩子添加到父实体中的列表中

                    transaccion.Operaciones.Add(operacion); 

                    opercionID ++; 

                }

 

                //在这里,我将'master'实体添加到List< master实体类型> 

                transaccion_List.Add(transaccion); 

                i ++; 

            }

 

            //最后,我返回主"实体的列表

            //我在这里进行调试检查,只有*一位父母(列表中的一项)

            //具有* all *的子代结构良好... 

 

           返回transaccion_List.AsQueryable();

        }

 

如果有人在上面的代码中看到一些不适当的行,那就太好了.


Hi to all, 

I've been struggling with this issue for days and can not make it work! From reading posts in the forum, I can understand some folks here have made this possible in LS. 

I use ria extensible and it works nice always. However, I need to model two entities and associate them in one to many way. I have not made this before. 

I have read posts like this: 

http://social.msdn.microsoft.com/Forums/en/lightswitchgeneral/thread/e7c5273b-ce22-4b20-9d9e-f8be123f938f

which contains the way associations should be expressed in ria. 

However, I will post my code so somebody can help me find what I do wrong. 

These are my entities in ria: 

public class Transaccion

    {

        [Key]

        public int ID { get; set; }

        (some properties here ...) 

        [Include]

        [Association("Transaccion_Operaciones", "ID", "TransaccionID", IsForeignKey = false)]

        public ICollection<Operacion> Operaciones { get; set; }

    }

 

    public class Operacion

    {

        [Key]

        public int ID { get; set; }

        public int TransaccionID { get; set; }

        (some properties here ...) 

        [Include]

        [Association("Transaccion_Operaciones", "TransaccionID", "ID", IsForeignKey = true)]

        public Transaccion Transaccion { get; set; }

    }

In my query, I read data from entities in model (external db) and fill these two entities using a List. Before issuing 

解决方案

Hi, 

I have still been unable to resolve my issue. I think people that have read this post have checked the way entity classes are coded in c# and find then correct. 

So I have decided to post a simplified version of the queries that build and return the parent-child entities to see if you can spot any possible causes of error; I mean the reason why children *do not get*  to client screen in LS. 

This is the code I used to write my queries: 

[Query(IsDefault = true)]

        public IQueryable<Transaccion> GetTransaccion()

        {

            List<Transaccion> list = new List<Transaccion>();

            return list.AsQueryable();

        }

 

[Query(IsDefault = true)]

        public IQueryable<Operacion> GetOperacion()

        {

            List<Operacion> list = new List<Operacion>();

            return list.AsQueryable();

        }

 

        public IQueryable<Transaccion> GetTransaccionByFilter(int? cia, string referencia, string origen)

        {

 

            // with parameters I build 'filter' string ... 

 

            var query = from t in Context.TransaccionesFinancieras.

                        Include("TransaccionesFinancieras_Operaciones").

                        Where(filter) 

                        select t;

 

            short i = 0;

            Transaccion transaccion;

            List<Transaccion> transaccion_List = new List<Transaccion>();

 

 

            foreach (TransaccionesFinanciera t in query)

            {

                transaccion = new Transaccion()

                {

                    ID = i,

                    // here I fill my 'parent' entity properties and instantiate Operaciones as a List 

                    Operaciones = new List<Operacion>()

 

                };

 

                Operacion operacion;

                short operacionID = 0;

 

                foreach (TransaccionesFinancieras_Operacione o in t.TransaccionesFinancieras_Operaciones)

                {

                    operacion = new Operacion()

                    {

                        ID = operacionID,

                        TransaccionID = transaccion.ID,

                        // more properties get its value here                    

                    };

                    // this is the property for 'parent' entity 

                    operacion.Transaccion = transaccion; 

 

                    // then I add the child to the List in parent entity 

                    transaccion.Operaciones.Add(operacion); 

                    operacionID++; 

                }

 

                // here I add 'master' entity to List<master entity Type> 

                transaccion_List.Add(transaccion); 

                i++; 

            }

 

            // finally I return list of 'master' entities 

            // I check with debug here and there is *only* one parent (one item in List)

            // with *all* its children well built ... 

 

            return transaccion_List.AsQueryable();

        }

 

It'd be wonderful if somebody see some inappropriate lines in above code. 


这篇关于Ria +协会-如何进行这项工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆